May 14, 2008 at 9:57 am
Hi does anyone know how to create a query in SQL 2000 or 2005 to get the year and week number together for a date i.e. the 01/01/2008 would be 200801. I know how to get them seperately using datepart but i need them joined together.
Any help would be much appreciated.
May 14, 2008 at 10:06 am
select ltrim(year('01/01/2008')) + right('0' + ltrim(datepart(week, '01/01/2008')), 2)
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
May 14, 2008 at 10:14 am
If you want a whole bunch of them, you should consider making use of this date function...
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61519
select DATE, ISO_YEAR_WEEK_NO from dbo.F_TABLE_DATE('1/1/2008', '1/1/2009')
Better still, use that function to create a permanent, fully-indexed table, and then use that.
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
May 14, 2008 at 12:51 pm
select year(getdate()) * 100 + datepart(week,getdate()) as year_week
May 14, 2008 at 3:37 pm
Thanks guys i will try your suggestions and let you know the outcome.
May 14, 2008 at 10:19 pm
Ack... double post... :sick:
http://www.sqlservercentral.com/Forums/Topic500305-5-1.aspx?Update=1
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply