Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Get Month Name Expand / Collapse
Author
Message
Posted Friday, February 8, 2008 12:23 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 15, 2012 4:29 PM
Points: 19, Visits: 76
Hi all
Is there any best way to get month name in SQL SERVER 2005.
I know that we can do this using our own function, but just i want to conform that if SQL SERVER provide any function for month name if we have month number i.e. 1,2..12

Thanks


Warm Regards,
Shakti Singh Dulawat
Before printing, think about the environment
Do the impossible, and go home early.
Post #453088
Posted Friday, February 8, 2008 1:30 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:54 AM
Points: 42,768, Visits: 35,867
SQL has a DateName function, however it takes a datetime as a parameter, not a number

SELECT DATENAME(month, GETDATE()) AS 'Month Name'
returns
Month Name
------------------------------
February



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #453098
Posted Friday, February 8, 2008 1:45 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 15, 2012 4:29 PM
Points: 19, Visits: 76
Thanks
Thats good
But is there is way so we can get month name using month number.


Warm Regards,
Shakti Singh Dulawat
Before printing, think about the environment
Do the impossible, and go home early.
Post #453100
Posted Friday, February 8, 2008 1:52 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 7:54 AM
Points: 42,768, Visits: 35,867
Not directly, though you could convert the month number inot a date.

SELECT DATENAME(month,'1900/' + CAST(monthNumber AS VARCHAR(2)) + '/01')



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #453101
Posted Friday, February 8, 2008 10:36 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 15, 2012 4:29 PM
Points: 19, Visits: 76
Thanks very much

Warm Regards,
Shakti Singh Dulawat
Before printing, think about the environment
Do the impossible, and go home early.
Post #453558
Posted Tuesday, March 11, 2008 8:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, June 2, 2009 4:42 AM
Points: 1, Visits: 23
thank you GilaMonster...
Post #467475
Posted Tuesday, March 11, 2008 9:15 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:42 AM
Points: 36,955, Visits: 31,463
GilaMonster (2/8/2008)
Not directly, though you could convert the month number inot a date.

SELECT DATENAME(month,'1900/' + CAST(monthNumber AS VARCHAR(2)) + '/01')


Heh, too much VARCHAR in that for me, Gail... :P

SELECT DATENAME(mm,DATEADD(mm, MonthNumber-1,0))


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #467495
Posted Wednesday, March 11, 2009 6:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 6, 2009 9:52 PM
Points: 1, Visits: 6
thanks a ton.....
it helped. :D
Post #673192
Posted Wednesday, March 11, 2009 9:33 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:42 AM
Points: 36,955, Visits: 31,463
You bet... thanks for the feedback.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #673916
Posted Thursday, March 12, 2009 3:30 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 8:23 AM
Points: 2,025, Visits: 2,521
A little modification in Jeff's code.

SELECT DateName(mm,DATEADD(mm,MonthNumber,-1))


karthik
Post #674030
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse