Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need a Month Name

Author  Topic 

divyaram
Posting Yak Master

180 Posts

Posted - 2010-04-21 : 06:22:14
Hi All,


I have a table with two columns, one column with month and 2 column with some other details MOnth column have only values from 1 to 12. i need a function to display the corresponding monthname according to the value in Month column, like for 1 it should be january, for 2 it should be feb like that.
Can anyone help me.....

Regards,
Divya

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:28:09
yup. just do like

SELECT [month] AS MnthNo,DATENAME(mm,DATEADD(mm,[month]-1,0)) AS MnthName FROM YourTable




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-21 : 06:28:43
select
case [month]
when 1 then 'jan'
when 2 then 'feb'
...
when 12 then 'dec'
end as [month],
other columns...
from table
where ...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-21 : 06:30:47
quote:
Originally posted by visakh16

yup. just do like

SELECT [month] AS MnthNo,DATENAME(mm,DATEADD(mm,[month]-1,0)) AS MnthName FROM YourTable




------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Ok, that's more elegant


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:31:15
thanks

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

divyaram
Posting Yak Master

180 Posts

Posted - 2010-04-21 : 06:37:25
quote:
Originally posted by visakh16

thanks

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





wow really helpfull code

Regards,
Divya
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-21 : 06:40:21
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -