Hi ,
I have query where I am getting time difference first of all in terms of hours as:
DECLARE @L_TIME_DIFF INT
SET @L_TIME_DIFF= (DATEDIFF(hh, '05/09/2014', '05/12/2014'))
i.e. subtracting 12th may - 9th may and getting diff in hours ..in this case it will be 3*24 = 72 hours
All fine till here. Now next step I need to subtract from this 72 hours if falling any week off day. It can be Friday, it can be Saturday, or Sunday, or Half day Saturday, or Half Day Sunday, or Full 2 days Saturday/Sunday .
The above scenario is decided based on one table [CALENDER_WORKINGDAYS] which looks like below :
CAL_WORKING_DAY | CAL_AM | CAL_PM | CAL_SEQ_NO |
Monday | 1 | 1 | 1 |
Tuesday | 1 | 1 | 2 |
Wednesday | 1 | 1 | 3 |
Thursday | 1 | 1 | 4 |
Friday | 0 | 0 | 5 |
Saturday | 1 | 1 | 6 |
Sunday | 1 | 1 | 7 |
So in this case, if you look at friday (CAL_AM=0 and CAL_PM=0) this measn friday full day holiday for some country.
Hence I need to : 72 - 24 = 48 Hours should be my output.
In another scenario, let s say some country work half day Saturday and Sunday full day off.
So my output should be : 72 - 36 (because 24 hours for sunday off, and 12 hours for saturday half day off) =36 should be my output
and so on..
Can you help to build such query based on the above table given ?
Thanks