SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DatePart week and year end


DatePart week and year end

Author
Message
pbaldy
pbaldy
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 71
I have this in a stored procedure (SS2005):

DATEPART(ww,Driver_summary.Dor_date) AS WeekNum

When run for a period of 12/30/12 through 1/5/13, it is returning 53 for the days in 2012 and 1 for the days in 2013. Is there a way to get the function to return the same week number for any given Sunday-Saturday time frame, regardless of whether it falls over a year end?

Thanks,

Paul



J Livingston SQL
J Livingston SQL
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5693 Visits: 35477
suggest you search this site (and others) for "Calendar tables"....

weeks are generally peculiar to the industry/company...there is a lot of help out there if you care to read.

regards

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

pbaldy
pbaldy
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 71
I appreciate your quick reply. I will do that research. The DatePart() function in Access has arguments that let you control this (specifically the "firstweekofyear" argument). I had hoped SQL Server's did as well and I was just missing it.



J Livingston SQL
J Livingston SQL
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5693 Visits: 35477
pbaldy (1/9/2013)
I appreciate your quick reply. I will do that research. The DatePart() function in Access has arguments that let you control this (specifically the "firstweekofyear" argument). I had hoped SQL Server's did as well and I was just missing it.


try this for a start

http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

anthony.green
anthony.green
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10538 Visits: 6378
This calendar table might also help you out

http://www.sqlservercentral.com/scripts/Date/68389/



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


octagonbi
octagonbi
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 5
I just came across this and created a case statement to get around this.

CASE WHEN DATEPART(ww,Driver_summary.Dor_date)=53 THEN 1 ELSE DATEPART(ww,Driver_summary.Dor_date) END AS WeekNum
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search