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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Last Working Week

Author  Topic 

dibblejon
Starting Member

36 Posts

Posted - 2010-06-02 : 10:24:22
Hi
I 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 total
FROM dbo.CurrentMonthSLHIST
WHERE
(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?
Go to Top of Page

dibblejon
Starting Member

36 Posts

Posted - 2010-06-02 : 10:27:51
Yes
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -