Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
HiI need this query to always select data from the last working week. My current code returns the past 7 days on a rolling basis. Would appreciate if someone could help, thanks
SELECT OPERATOR, SUM(QTY) AS totalFROM dbo.CurrentMonthSLHISTWHERE (PART IN 'RG123', 'RG124', 'RG125', 'RG126', 'SCH101', 'SCH102')) AND (DATE >= DATEADD(DAY, - 7, GETDATE()))GROUP BY OPERATOR
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts
Posted - 2010-06-02 : 10:25:49
What consititues the "last working week"? Is it from Monday to Friday of the previous week?
dibblejon
Starting Member
36 Posts
Posted - 2010-06-02 : 10:27:51
Yes
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts
Posted - 2010-06-02 : 10:29:33
See if this function from MVJ helps. It returns the First day of week based on the date passed. You can modify it to return the first day of previous week.http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47307