SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Show results for first day each week
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlpal2007
Posting Yak Master

184 Posts

Posted - 02/27/2013 :  11:43:39  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8760 Posts

Posted - 02/27/2013 :  12:32:37  Show Profile  Visit webfred's Homepage  Reply with Quote
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
Constraint Violating Yak Guru

USA
346 Posts

Posted - 02/27/2013 :  17:28:57  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000