Using SQL Server 2000
Table1
ID Salary (Monthly) perday (salary)
001 3000 100
002 1500 50
003 4500 150
Salary, perday columns are of datatype float
Table2
ID Date Latetime (HH:mm)
001 01/02/2012 00:15
001 02/02/2012 00:10
001 03/02/2012 00:45
001 04/02/2012 00:29
001 05/02/2012 01:00
002 11/03/2012 00:02
002 12/03/2012 00:20
002 13/03/2012 00:29
002 14/03/2012 01:00
002 10/03/2012 01:30
002 10/03/2012 02:00
I want to deduct the salary amount according to the count of latetime.
Condition
01 to 29 mintues late condition
- If User late on 1st time no deduction
- If user late on 2nd time 10% deduction of perday salary
- If user late on 3rd time 25% deduction of perday salary
- If user late on 4th time and above 50% deduction of perday salary
30 mintues to 1 hour late condition
- If User late on 1st time no deduction
- If user late on 2nd time 50% deduction of perday salary
- If user late on 3rd time 100% deduction of perday salary
- If user late on 4th time and above 150% deduction of perday salary
Expected Output for table2
4th onwards
ID Ist 2nd 3rd days Amount Deducted
001 0 10 50 2 250 310
002 0 10 10 1 100 120
Output explanation
User 001 late for 5 times as a Count(latetime) from table2
- 1st time late for 00:15 minutes – no deduction
- 2nd time late for 00:10 minutes, so late time in between 01 to 29, so 10 % of perday salary deduction ‘1st time (01 to 29)
- 3rd time late for 00:45 minutes, so late time in between 30 to 01 hours, so 50 % of perday salary deduction ‘1st time (30 to 01)
- 4th time late for 00:29 minutes, so late time in between 01 to 29, so 50 % of perday salary deduction ‘2nd time (01 to 29)
- 5th time late for 01:00 minutes, so late time in between 30 to 01 hours, so 150 % of perday salary deduction ‘1st time (30 to 01)
How to create a query for the above conditions?
1 Answer