July 19, 2007 at 9:06 pm
Hi Guys
I have got a date for ex '1/11/2005' I need to create a separate column called 'month&year' which should display '11/2005'
And I also need to create another column called quarter which should display the current quarter for the date for ex in this case, it should display 4.
Cheers
July 19, 2007 at 10:08 pm
This one is pretty easy to figure out if you check BOL first... read up on the entry on date functions. But this should work:
SELECT CONVERT(VARCHAR, MONTH(mydate)) + '/' + CONVERT(VARCHAR, YEAR(mydate)) AS MonthAndYear, DATEPART(qq, mydate) AS Quarter
FROM mytable
July 19, 2007 at 10:44 pm
Different slant on the month/year...
SELECT RIGHT(CONVERT(CHAR(10),GETDATE(),103),7)
--Jeff Moden
Change is inevitable... Change for the better is not.
July 19, 2007 at 10:46 pm
By the way... these new columns should be "computed columns"... not real ones. Computed columns can be indexed if they are deteminate and they're self updating...
--Jeff Moden
Change is inevitable... Change for the better is not.
July 23, 2007 at 3:01 pm
Thanks for that Jeff
It works perfectly!!!
Keep up the good work
Cheers
July 23, 2007 at 3:28 pm
Jeff is SQL MVP
July 23, 2007 at 6:00 pm
Good to know that!!!
July 23, 2007 at 6:08 pm
Thanks Wutang , but, nope... just a regular ol' SQL guy answering questions if I can.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 23, 2007 at 6:40 pm
The modesty doesn't suite you
There are many people listen (read) to what you say (write)
N 56°04'39.16"
E 12°55'05.25"
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply