Frage

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!

War es hilfreich?

Lösung

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

Andere Tipps

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!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top