March 2, 2006 at 7:45 pm
got it to work , as u have said, datepart works like a charm, manage to get mth and week out of it. however, datepart only allows 2 arguments so i can't input week and year together in 1 column. is it possible to have 2 dateparts, each extracting year and month, and then combining the data together in one column in the same datasheet. i believe a stored procedure/view is needed here? or are there other alternatives?
Thanks, Eric
March 3, 2006 at 12:54 am
Yes, and you don't need a SP for that. You can do it directly in the query. Result of DATEPART is a number, so you just have to convert that to string and concatenate the two strings together. Following SQL produces "week/year" format, i.e. result is in one column (for current date, result is 9/2006):
SELECT CONVERT(varchar(2),DATEPART(wk, @date)) + '/' + CONVERT(varchar(4),DATEPART(yy,@date))
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply