September 1, 2004 at 5:21 pm
I don't want to use case statement but want to convert numeric field to month name. Ex:
Month Month_Name
1 January
2 Feburary
3 March
and etc... Thanks for your help.
Minh
September 1, 2004 at 5:37 pm
I figured out a stupid way to do it. But if someone shows me a better way, I will be really appreciate.
My way is:
select datename(mm,convert(datetime,[month]+'/1/00'))
from mytable
September 1, 2004 at 10:07 pm
Here's another stupid way:
SELECT DATENAME(month, @month * 28)
-- where @month contains an integer between 1 and 12.
Can't see any more obvious way. It would perhaps be more elegant to write a UDF.
Phil
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 2, 2004 at 8:02 am
How often are you going to need to do this conversion? If it's not often, do the conversions suggested. If you are going to do it often, there's the possibility you will need it in different scripts. In that case I suggest creating a table to hold the information.
CREATE TABLE myMonths
AS
(MonthInt INT,
MonthName VARCHAR(9))
Once you insert the values, you can do an table join and select the MonthName where the MonthInt equals whatever you want.
-SQLBill
September 3, 2004 at 2:48 am
For what its worth...
SQLBill's solution would allow for situations where you don't have 12 months in a year (e.g. in accounting scenarios you may have 13). I would go with that!
Jamie Thomson
http://sqlblog.com/blogs/jamie_thomson
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply