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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Show results for first day each week

Author  Topic 

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2013-02-27 : 11:43:39
Hello All,

Can you please tell me how to write query to show results on first day of each week?

For example:

Rundate document#
02/01/2013 100
02/02/2013 110
02/03/2013 140
02/04/2013 166
02/05/2013 170
02/06/2013 189
02/07/2013 190
02/08/2013 220
02/10/2013 234
02/11/2013 256
02/12/2013 278
02/13/2013 290
02/14/2013 330
02/15/2013 340
02/16/2013 367
02/17/2013 380
02/18/2013 390
02/19/2013 430
02/20/2013 460

Result should look like -
02/04/2013 166
02/11/2013 256
02/18/2013 390

The first day of week is Monday.

Thanks,



webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-02-27 : 12:32:37
try:
select * from table where datename(weekday,rundate)='Monday'


Too old to Rock'n'Roll too young to die.
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-02-27 : 17:28:57
This is slightly more efficient, and avoids any potential language or spelling issues:


SELECT *
FROM dbo.tablename
WHERE
DATEDIFF(DAY, 0, runDate) % 7 = 0

Go to Top of Page
   

- Advertisement -