Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include Weekends into Monday (Include Sat. & Sun. with Mon.) Data

Status
Not open for further replies.

supportsvc

Technical User
Jan 24, 2018
249
US
Hello,
So I found a lot of EXCLUDE weekends, which helped since one report requires NOT to include weekends into the calculation.

However, on other reports weekends need to be INCLUDED but combined in with Monday.
So when it reports on Monday, the Sat. and Sun. figures calculates with Mon. data.

I found this but it doesn't make much sense to me, in fact it doesn't look similar in SQL syntax.
Such as current_date and day

Here's the link. It says it's SQL but I'm such a novice I can't make sense of it.
Running a Mon-Fri report to include weekend data

I tried to change the words to what I am familiar with, however it's insufficient
Code:
OrderDate IN (GetDate() – interval 
case dayofweek(getdate()) 
 when 1 /* mon */ then 2 
 when 2 /* tue */ then 1 
 when 3 /* wed */ then 1 
 when 4 /* thu */ then 1 
 when 5 /* fri */ then 1 
else null end  day, 
getdate() – interval 
case dayofweek(getdate()) 
 when 2 /* tue */ 
 then 2 else null end  day, 
getdate() – interval  
case dayofweek(current_date) 
 when 2 /* tue */ then 2 else null end  day)

Or perhaps there's a better way?
 
I found this and it's putting everything to Monday, 4/9

Code:
CASE WHEN datename(dw , getdate() - 6) = 'Monday' THEN + dateadd(dd , - 1 , getdate() - 6) + dateadd(dd , - 2 , getdate() - 6) ELSE dateadd(dd , 1 , getdate() - 6) END

I set a between getdate()-8 and getdate()-1 to test this week and today as yesterday (Friday) to see if the above code works correctly

i am seeing orders from Sat. 4/7 through Fri., 4/13, which is what it should show given the Between filter

However the code I'm trying to make work is to show the Sat., 4/7 and Sun., 4/8 order dates to show as Mon., 4/9 along with the actual 4/9 orders and the other days after 4/9 to show their actual order dates. But they are all showing as Mon., 4/9
 
Figure it out with the following

Create function as described here

Then
Code:
CASE WHEN { fn DAYOFWEEK(OrderDate) } IN (1 , 7) THEN dbo.DAYSADDNOWK(GETDATE() - 7 , 2) ELSE OrderDate END as weekdate

Last Sat. and Sun. shows last Mon. date so that Sat., Sun., counts toward Mon., 4/9
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top