Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mimuk
Starting Member
19 Posts |
Posted - 2014-08-26 : 05:56:45
|
I have a sql query which checks for records in 2 days time.However if I run this on a Thursday or Friday, it will display weekend date, which I want to exclude.Can someone help so that it excludes Sat/Sun from query so if run on a friday it displays Tuesdays results?Many thanks in advance.Query is:SELECT DISTINCT Orde_OrderQuoteId, orde_reference, orde_description, orde_status, orde_grossamt, orde_grossamt_CID FROM vlistorders WHERE (DATEPART(DY, orde_expiredelivery) = DATEPART(DY, DATEADD(DD, 2, GETDATE())) AND DATEPART(YY, orde_expiredelivery) = DATEPART(YY, DATEADD(DD, 1, GETDATE()))) AND Orde_OrderQuoteId IS NOT NULL ORDER BY Orde_OrderQuoteId |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-08-26 : 10:18:19
|
Change your WHERE clause for the date arithmetic to this:WHERE orde_expiredelivery = DATEADD(dd,CASE WHEN DATEDIFF(dd,'19000101',GETDATE())%7 IN (3,4) THEN 4 ELSE 2 END,CAST(GETDATE() AS DATE)) |
|
|
mimuk
Starting Member
19 Posts |
Posted - 2014-08-26 : 10:46:30
|
Perfect thanks James, works a treat |
|
|
|
|
|
|
|