﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / SQL Server Newbies  / Get Month Name / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 06:31:49 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Thanks for the feedback, folks.</description><pubDate>Mon, 03 Sep 2012 10:22:51 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Many thanks for all the answers here particularly the ones from Jeff and Karthik.  They enable me to get rid of a lot of CASE statements! :-)</description><pubDate>Mon, 03 Sep 2012 02:16:01 GMT</pubDate><dc:creator>Fear Naught</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Jeff ... Thanks a lot for your explanation.</description><pubDate>Sun, 02 Sep 2012 20:20:49 GMT</pubDate><dc:creator>yanto 93637</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[quote][b]yanto 93637 (8/30/2012)[/b][hr]see link here please[url=http://sqltosql.blogspot.com/2012/08/sql-month-name.html]http://sqltosql.blogspot.com/2012/08/sql-month-name.html[/url][/quote]Since it's in the article you posted a link for, let me show you that you don't need the complexity of a While Loop or Dynamic SQL.Here's the code from the article you posted...[code="sql"]declare @start int,@end intdeclare @qry nvarchar(100)declare @summary nvarchar(1200)set @start=1set @end=13set @summary=''while not (@start=@end)    begin        if @start=@end-1            set @qry=(select ('SELECT ('+convert(nvarchar,@start)+')monthNumber,            DateName(mm,DATEADD(mm,'+convert(nvarchar,@start)+',-1))monthName')qry)        else            set @qry=(select ('SELECT ('+convert(nvarchar,@start)+')monthNumber,            DateName(mm,DATEADD(mm,'+convert(nvarchar,@start)+',-1))monthName             union ')qry)        set @summary=@summary+@qry                set @start=@start+1    end    exec (@summary)[/code]The following snippet does the same thing without the loop or the dynamic SQL.[code="sql"]WITHcteTally AS( SELECT TOP 12        N = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))   FROM sys.all_columns) SELECT MonthNumber = N,        MonthName   = DATENAME(mm,DATEADD(mm,N,-1))   FROM cteTally;[/code]Of course, since this is an SQL Server 2000 forum, the code above won't work in SQL Server 2000.  The following will, though... and, since it uses a Tally Table, the code becomes even more simple and works in all versions of SQL Server.[code="sql"] SELECT MonthNumber = N,        MonthName   = DATENAME(mm,DATEADD(mm,N,-1))   FROM dbo.Tally  WHERE N &amp;lt;= 12;[/code]For more information on what a Tally Table (or cteTally) is and how it can be used to replace certain loops in a very high performance fashion, please see the following article.[url]http://www.sqlservercentral.com/articles/T-SQL/62867/[/url]</description><pubDate>Fri, 31 Aug 2012 08:25:01 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>see link here please[url=http://sqltosql.blogspot.com/2012/08/sql-month-name.html]http://sqltosql.blogspot.com/2012/08/sql-month-name.html[/url]</description><pubDate>Thu, 30 Aug 2012 21:29:15 GMT</pubDate><dc:creator>yanto 93637</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>see link here please http://sqltosql.blogspot.com/2012/08/sql-month-name.html</description><pubDate>Thu, 30 Aug 2012 21:27:39 GMT</pubDate><dc:creator>yanto 93637</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>ton of Thanks</description><pubDate>Thu, 01 Jul 2010 20:56:39 GMT</pubDate><dc:creator>vishal.jani</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[quote][b]trishdiep (6/12/2010)[/b][hr]Awesome, thanks so much to Jeff and Karthik!I want to say thank you to Jeff for helping so many of us, Much appreciated!:-)[/quote]Thank you very much for the feedback.  I appreciate it.  I do have to say that I'm not alone in this, though.  Lot's of good folks help others every day on this and many other forums.  For that matter, look at how many people came up with good ideas or additional information on this thread alone.  I'm humbled in their presence. :-)</description><pubDate>Sat, 12 Jun 2010 10:26:01 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Awesome, thanks so much to Jeff and Karthik!I want to say thank you to Jeff for helping so many of us, Much appreciated!:-)</description><pubDate>Sat, 12 Jun 2010 09:07:28 GMT</pubDate><dc:creator>trishdiep</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[quote][b]Venkatesan Prabu (6/6/2010)[/b][hr]drop table sample_tablecreate table sample_table (id int, dat datetime)insert into sample_table values(1,getdate())select * from sample_tableselect id,dat from sample_table where datename(month,dat)='June'----------------------------------------- id            dat----------------------------------------- 1	       2010-06-07 10:54:52.607-----------------------------------------Cheers,Venkatesan Prabu .Jhttp://venkattechnicalblog.blogspot.com/[/quote]Ummm... I don't get it.  How does that deal with the original request of converting month numbers to month names?</description><pubDate>Sun, 06 Jun 2010 21:28:53 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>drop table sample_tablecreate table sample_table (id int, dat datetime)insert into sample_table values(1,getdate())select * from sample_tableselect id,dat from sample_table where datename(month,dat)='June'----------------------------------------- id            dat----------------------------------------- 1	       2010-06-07 10:54:52.607-----------------------------------------Cheers,Venkatesan Prabu .Jhttp://venkattechnicalblog.blogspot.com/</description><pubDate>Sun, 06 Jun 2010 18:58:47 GMT</pubDate><dc:creator>Venkatesan Prabu</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>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_valuesWHERE Type = 'P' and Number &amp;lt; 12</description><pubDate>Fri, 21 May 2010 00:55:37 GMT</pubDate><dc:creator>mandarkavishwar</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Gailyou rock!but you knew that alreadythis also works in SQL Server 2000</description><pubDate>Tue, 20 Apr 2010 13:41:18 GMT</pubDate><dc:creator>Seggerman-675349</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[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.[code="sql"]set language spanishselect DATENAME(m,DATEADD(m,1,-1))--Eneroselect DATENAME(m,DATEADD(m,2,-1))--Febreroselect DATENAME(m,DATEADD(m,3,-1))--Marzoselect DATENAME(m,DATEADD(m,4,-1))--Abril[/code]</description><pubDate>Wed, 07 Apr 2010 22:49:10 GMT</pubDate><dc:creator>Garadin</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>The character conversion will slow things down quite a bit if you happen to use the for batch programming on millions of rows.</description><pubDate>Fri, 02 Apr 2010 18:11:51 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Here is one line solution in my implementation.[url=http://praveenbattula.blogspot.com/2009/04/how-to-know-month-name-from-month-index.html]http://praveenbattula.blogspot.com/2009/04/how-to-know-month-name-from-month-index.html[/url]</description><pubDate>Mon, 29 Mar 2010 02:43:09 GMT</pubDate><dc:creator>battula.praveen</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Super Logic..Keep Rocking:)</description><pubDate>Mon, 18 Jan 2010 02:36:12 GMT</pubDate><dc:creator>rajesh.vellore</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[quote][b]karthikeyan (3/12/2009)[/b][hr]A little modification in Jeff's code.SELECT DateName(mm,DATEADD(mm,MonthNumber,-1))[/quote]Yep... good call.</description><pubDate>Thu, 12 Mar 2009 18:55:21 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>A little modification in Jeff's code.SELECT DateName(mm,DATEADD(mm,MonthNumber,-1))</description><pubDate>Thu, 12 Mar 2009 03:30:12 GMT</pubDate><dc:creator>karthik M</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>You bet... thanks for the feedback.</description><pubDate>Wed, 11 Mar 2009 21:33:16 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>thanks a ton.....it helped. :D</description><pubDate>Wed, 11 Mar 2009 06:50:49 GMT</pubDate><dc:creator>vikrammstein</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[quote][b]GilaMonster (2/8/2008)[/b][hr]Not directly, though you could convert the month number inot a date.SELECT DATENAME(month,'1900/' + CAST(monthNumber AS VARCHAR(2)) + '/01')[/quote]Heh, too much VARCHAR in that for me, Gail... :PSELECT DATENAME(mm,DATEADD(mm, MonthNumber-1,0))</description><pubDate>Tue, 11 Mar 2008 09:15:57 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>thank you GilaMonster...</description><pubDate>Tue, 11 Mar 2008 08:50:27 GMT</pubDate><dc:creator>raju.msoftprof</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>[b]Thanks very much[/b]</description><pubDate>Fri, 08 Feb 2008 22:36:23 GMT</pubDate><dc:creator>Shakti Singh Dulawat</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>Not directly, though you could convert the month number inot a date.SELECT DATENAME(month,'1900/' + CAST(monthNumber AS VARCHAR(2)) + '/01')</description><pubDate>Fri, 08 Feb 2008 01:52:47 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>ThanksThats goodBut is there is way so we can get month name using month number.</description><pubDate>Fri, 08 Feb 2008 01:45:42 GMT</pubDate><dc:creator>Shakti Singh Dulawat</dc:creator></item><item><title>RE: Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>SQL has a DateName function, however it takes a datetime as a parameter, not a numberSELECT DATENAME(month, GETDATE()) AS 'Month Name'returnsMonth Name                     ------------------------------ February</description><pubDate>Fri, 08 Feb 2008 01:30:28 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>Get Month Name</title><link>http://www.sqlservercentral.com/Forums/Topic453088-169-1.aspx</link><description>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..12Thanks</description><pubDate>Fri, 08 Feb 2008 00:23:40 GMT</pubDate><dc:creator>Shakti Singh Dulawat</dc:creator></item></channel></rss>