Question

I am using SQL server 2008 and have a query that runs daily.
Where [Order Date] = getdate()-1 I need a statement that will run Monday and sum the data for Friday, Saturday, and Sunday if that is even possible.

Thanks!

Was it helpful?

Solution

You could do something like this to select all the records within a certain range:

SELECT *
FROM your_table
WHERE ((DATEPART(dw, date_created) + @@DATEFIRST) % 7) IN (5,6,0)

Where:

5 = Friday
6 = Saturday
0 = Sunday

OTHER TIPS

select
case DATEPART(weekday,getdate())
when 2 then SUM(weekend just gone)
else SUM(yesterday)
end as totalamount
from
etc...

You need to check what weekday number is Monday though!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top