문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top