0

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!

jswan
  • 90
  • 7
  • 1
    Can you provide what you have so far? Whats making the report run on Monday? Could the report just tell you the tally from the last weekend, regardless if it was ran tues, wends? – cgatian Apr 02 '13 at 20:51
  • Related: http://stackoverflow.com/questions/15672274/roll-up-weekend-data-differently-from-weekdays/15672749#15672749 – Aaron Bertrand Apr 02 '13 at 20:58

2 Answers2

1

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

crazylpfan
  • 1,038
  • 7
  • 9
-2
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!

Lukos
  • 1,826
  • 1
  • 15
  • 29
  • Not all answers have to be complete, there is not enough to form a complete example. This is just to provide the basic answer using datepart. – Lukos Apr 02 '13 at 21:01
  • 1
    Can people not vote answers down without a comment? The code above is valid and as far as I can see answers the question. – Lukos Apr 18 '13 at 09:45