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 Thursday, March 12, 2009 6:55 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 3:36 PM
Points: 35,531, Visits: 32,114
karthikeyan (3/12/2009)
A little modification in Jeff's code.

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


Yep... good call.


--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 #674873
Posted Monday, January 18, 2010 2:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 27, 2010 3:09 AM
Points: 1, Visits: 28
Super Logic..Keep Rocking:)
Post #849025
Posted Monday, March 29, 2010 2:43 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, June 12, 2010 9:31 AM
Points: 12, Visits: 14
Here is one line solution in my implementation.
http://praveenbattula.blogspot.com/2009/04/how-to-know-month-name-from-month-index.html
Post #891657
Posted Friday, April 2, 2010 6:11 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 3:36 PM
Points: 35,531, Visits: 32,114
The character conversion will slow things down quite a bit if you happen to use the for batch programming on millions of rows.

--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 #896086
Posted Wednesday, April 7, 2010 10:49 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 2:20 PM
Points: 1,519, Visits: 4,081
[Edit] Ack, thought I had scrolled down all the way, apparently I was wrong.

Since I've posted anyways, might as well mention that doing it this way automatically adjusts for language settings.

set language spanish
select DATENAME(m,DATEADD(m,1,-1))--Enero
select DATENAME(m,DATEADD(m,2,-1))--Febrero
select DATENAME(m,DATEADD(m,3,-1))--Marzo
select DATENAME(m,DATEADD(m,4,-1))--Abril



Seth Phelabaum
Consistency is only a virtue if you're not a screwup.

Links: How to Post Sample Data :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
Post #899272
Posted Tuesday, April 20, 2010 1:41 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, July 7, 2014 7:19 AM
Points: 250, Visits: 537
Gail

you rock!

but you knew that already

this also works in SQL Server 2000
Post #907206
Posted Friday, May 21, 2010 12:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, May 2, 2013 1:50 AM
Points: 167, Visits: 37
Similarly if you want to list all the month names for a year using a T-SQL statement, you can do this:

SELECT Number + 1 as [MonthNumber],
DateName(mm,DATEADD(mm,Number,0)) as [MonthName]
FROM master..spt_values
WHERE Type = 'P' and Number < 12
Post #925702
Posted Sunday, June 6, 2010 6:58 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, April 15, 2012 7:06 AM
Points: 122, Visits: 205
drop table sample_table
create table sample_table (id int, dat datetime)
insert into sample_table values(1,getdate())

select * from sample_table
select id,dat from sample_table where datename(month,dat)='June'
-----------------------------------------
id dat
-----------------------------------------
1 2010-06-07 10:54:52.607
-----------------------------------------

Cheers,
Venkatesan Prabu .J
http://venkattechnicalblog.blogspot.com/


Thanks and Regards,
Venkatesan Prabu, :P
My Blog:

http://venkattechnicalblog.blogspot.com/
Post #933306
Posted Sunday, June 6, 2010 9:28 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 3:36 PM
Points: 35,531, Visits: 32,114
Venkatesan Prabu (6/6/2010)
drop table sample_table
create table sample_table (id int, dat datetime)
insert into sample_table values(1,getdate())

select * from sample_table
select id,dat from sample_table where datename(month,dat)='June'
-----------------------------------------
id dat
-----------------------------------------
1 2010-06-07 10:54:52.607
-----------------------------------------

Cheers,
Venkatesan Prabu .J
http://venkattechnicalblog.blogspot.com/


Ummm... I don't get it. How does that deal with the original request of converting month numbers to month names?


--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 #933320
Posted Saturday, June 12, 2010 9:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 1:35 PM
Points: 6, Visits: 49
Awesome, thanks so much to Jeff and Karthik!
I want to say thank you to Jeff for helping so many of us, Much appreciated!
Post #936441
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse