Hi,
I have a attendance table which is given below.
CREATE TABLE [dbo].[Attendance](
[Attendance_No] [numeric](18, 0) NULL,
[Attendance_Date] [date] NULL,
[Attendance_EmpNo] [numeric](18, 0) NULL,
[Attendance_DailyWages] [numeric](18, 2) NULL,
[Attendance_InTime] [datetime] NULL,
[Attendance_OutTime] [datetime] NULL
) ON [PRIMARY]
GO
The Data inside table is given below.
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (1,'2022-01-01',1,20.5,'2022-01-01 08:17 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (2,'2022-01-01',1,20.5,'2022-01-01 08:20 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (3,'2022-01-01',1,20.5,'2022-01-01 08:40 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (4,'2022-01-01',1,20.5,'2022-01-01 08:50 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (5,'2022-01-01',1,20.5,'2022-01-01 08:52 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (6,'2022-01-01',2,20.5,'2022-01-01 08:17 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (7,'2022-01-01',2,20.5,'2022-01-01 08:20 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (8,'2022-01-01',2,20.5,'2022-01-01 08:40 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (9,'2022-01-01',2,20.5,'2022-01-01 08:50 AM','2022-01-01 03:30 PM')
INSERT INTO [Attendance]([Attendance_No],[Attendance_Date],[Attendance_EmpNo],[Attendance_DailyWages],[Attendance_InTime],[Attendance_OutTime])
VALUES (10,'2022-01-01',2,20.5,'2022-01-01 08:52 AM','2022-01-01 03:30 PM')
GO
Below in tabular format.
Attendance_No | Attendance_Date | Attendance_EmpNo | Attendance_DailyWages | Attendance_InTime | Attendance_OutTime |
---|---|---|---|---|---|
1 | 2022-01-01 | 1 | 20.00 | 2022-01-01 08:17:00.000 | 2022-01-01 03:30:00.000 |
2 | 2022-01-02 | 1 | 20.00 | 2022-01-01 08:20:00.000 | 2022-01-01 03:30:00.000 |
3 | 2022-01-03 | 1 | 20.00 | 2022-01-01 08:40:00.000 | 2022-01-01 03:30:00.000 |
4 | 2022-01-04 | 1 | 20.00 | 2022-01-01 08:50:00.000 | 2022-01-01 03:30:00.000 |
5 | 2022-01-05 | 1 | 20.00 | 2022-01-01 08:52:00.000 | 2022-01-01 03:30:00.000 |
6 | 2022-01-01 | 2 | 20.00 | 2022-01-01 08:17:00.000 | 2022-01-01 03:30:00.000 |
7 | 2022-01-02 | 2 | 20.00 | 2022-01-01 08:20:00.000 | 2022-01-01 03:30:00.000 |
8 | 2022-01-03 | 2 | 20.00 | 2022-01-01 08:40:00.000 | 2022-01-01 03:30:00.000 |
9 | 2022-01-04 | 2 | 20.00 | 2022-01-01 08:50:00.000 | 2022-01-01 03:30:00.000 |
10 | 2022-01-05 | 2 | 20.00 | 2022-01-01 08:52:00.000 | 2022-01-01 03:30:00.000 |
How to check and apply the deduction based on Slabs.
Below is the Slabs.
Slab-A | ||
---|---|---|
1st Time | 08:15 AM to 08:30 AM | 5% |
2nd Time | 08:15 AM to 08:30 AM | 10% |
3rd Time | 08:15 AM to 08:30 AM | 15% |
4th Time | 08:15 AM to 08:30 AM | 100% |
Slab-B | ||
1st Time | 08:31 AM to 09:00 AM | 15% |
2nd Time | 08:31 AM to 09:00 AM | 25% |
3rd Time | 08:31 AM to 09:00 AM | 50% |
4th Time | 08:31 AM to 09:00 AM | 100% |
Need to Get the below output. then what will be the query
Attendance_No | Attendance_Date | Attendance_EmpNo | Attendance_DailyWages | Attendance_InTime | Attendance_OutTime | Slab | Slab Deduction Apply | Deduction Amount On Daily Wages |
---|---|---|---|---|---|---|---|---|
1 | 01-01-2022 | 1 | 20.5 | 1-1-22 8:17 AM | 1-1-22 3:30 AM | Slab-A | 1st Time-5% | 1.025 |
2 | 02-01-2022 | 1 | 20.5 | 1-1-22 8:20 AM | 1-1-22 3:30 AM | Slab-A | 2nd Time-10% | 2.05 |
3 | 03-01-2022 | 1 | 20.5 | 1-1-22 8:40 AM | 1-1-22 3:30 AM | Slab-B | 1st Time-15% | 3.075 |
4 | 04-01-2022 | 1 | 20.5 | 1-1-22 8:50 AM | 1-1-22 3:30 AM | Slab-B | 2nd Time-25% | 5.125 |
5 | 05-01-2022 | 1 | 20.5 | 1-1-22 8:52 AM | 1-1-22 3:30 AM | Slab-B | 3rd Time-50% | 10.25 |
6 | 01-01-2022 | 2 | 20.5 | 1-1-22 8:17 AM | 1-1-22 3:30 AM | Slab-A | 1st Time-5% | 1.025 |
7 | 02-01-2022 | 2 | 20.5 | 1-1-22 8:20 AM | 1-1-22 3:30 AM | Slab-A | 2nd Time-10% | 2.05 |
8 | 03-01-2022 | 2 | 20.5 | 1-1-22 8:40 AM | 1-1-22 3:30 AM | Slab-B | 1st Time-15% | 3.075 |
9 | 04-01-2022 | 2 | 20.5 | 1-1-22 8:50 AM | 1-1-22 3:30 AM | Slab-B | 2nd Time-25% | 5.125 |
10 | 05-01-2022 | 2 | 20.5 | 1-1-22 8:52 AM | 1-1-22 3:30 AM | Slab-B | 3rd Time-50% | 10.25 |
can be output in Image also
please help on this
regards,
Basit.