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.
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 10002/02/2013 11002/03/2013 14002/04/2013 16602/05/2013 17002/06/2013 18902/07/2013 19002/08/2013 22002/10/2013 23402/11/2013 25602/12/2013 27802/13/2013 29002/14/2013 33002/15/2013 34002/16/2013 36702/17/2013 38002/18/2013 39002/19/2013 43002/20/2013 460Result should look like -02/04/2013 166 02/11/2013 25602/18/2013 390The 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. |
|
|
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.tablenameWHERE DATEDIFF(DAY, 0, runDate) % 7 = 0 |
|
|
|
|
|