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
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 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
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27144 Visits: 41339
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
Old Hand
Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)Old Hand (328 reputation)

Group: General Forum Members
Points: 328 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
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27144 Visits: 41339
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
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62754 Visits: 8598
This calendar table might also help you out

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



How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


octagonbi
octagonbi
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 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