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 2005 Forums
 Transact-SQL (2005)
 Week No
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sanjay5219
Posting Yak Master

237 Posts

Posted - 12/03/2013 :  15:05:49  Show Profile  Reply with Quote
Hi All,

Is there a way if I can know the Week No.Datepart(wk,'') gives incremental no but I am looking week no based on month.

For example today is 4th Dec 2013 so I should get Week1

Please suggest

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 12/03/2013 :  15:24:51  Show Profile  Reply with Quote
nothing out of the box to do that. But maybe if you subtract the week number of the beginning of the month from the current week number?

declare @dt datetime; set @dt = '2013-12-04'
select datepart(week, @dt) - datepart(week, dateadd(month, datediff(month, 0, @dt), 0)) + 1

output:
1



Be One with the Optimizer
TG
Go to Top of Page

sanjay5219
Posting Yak Master

237 Posts

Posted - 12/04/2013 :  11:48:56  Show Profile  Reply with Quote
thanks
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 12/04/2013 :  13:09:35  Show Profile  Reply with Quote
you're welcome.

Be One with the Optimizer
TG
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30281 Posts

Posted - 12/05/2013 :  05:49:13  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT 1 + (DATEPART(DAY, @dt) - 1) / 7



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
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.06 seconds. Powered By: Snitz Forums 2000