Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Reg : subtracting weekoff day from the time difference

$
0
0

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_AMCAL_PMCAL_SEQ_NO
Monday111
Tuesday112
Wednesday113
Thursday114
Friday005
Saturday116
Sunday117

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

 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>