<p>I need the month+year from the datetime in SQL Server like 'Jan 2008'. I'm grouping the query by month, year. I've searched and found functions like datepart, convert, etc., but none of them seem useful for this. Am I missing something here? Is there a function for this?</p>

[{'answer_id': 45543, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 3, 'selected': False, 'text': "<p>That format doesn't exist. You need to do a combination of two things,</p>\n\n<pre><code>select convert(varchar(4),getdate(),100)  + convert(varchar(4),year(getdate()))\n</code></pre>\n"}, {'answer_id': 45548, 'author': 'robsoft', 'author_id': 3897, 'author_profile': 'https://Stackoverflow.com/users/3897', 'pm_score': 7, 'selected': True, 'text': '<p>If you mean you want them back as a string, in that format;</p>\n\n<pre><code>SELECT \n  CONVERT(CHAR(4), date_of_birth, 100) + CONVERT(CHAR(4), date_of_birth, 120) \nFROM customers\n</code></pre>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="noreferrer">Here are the other format options</a></p>\n'}, {'answer_id': 45603, 'author': 'HS.', 'author_id': 618, 'author_profile': 'https://Stackoverflow.com/users/618', 'pm_score': 7, 'selected': False, 'text': "<pre><code>select \ndatepart(month,getdate()) -- integer (1,2,3...)\n,datepart(year,getdate()) -- integer\n,datename(month,getdate()) -- string ('September',...)\n</code></pre>\n"}, {'answer_id': 446383, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': "<pre><code>( Month(Created) + ',' + Year(Created) ) AS Date\n</code></pre>\n"}, {'answer_id': 446406, 'author': 'Mike Geise', 'author_id': 43380, 'author_profile': 'https://Stackoverflow.com/users/43380', 'pm_score': 4, 'selected': False, 'text': '<p>Funny, I was just playing around writing this same query out in SQL Server and then LINQ.</p>\n\n<pre><code>SELECT \n    DATENAME(mm, article.Created) AS Month, \n    DATENAME(yyyy, article.Created) AS Year, \n    COUNT(*) AS Total \nFROM Articles AS article \nGROUP BY \n    DATENAME(mm, article.Created), \n    DATENAME(yyyy, article.Created) \nORDER BY Month, Year DESC\n</code></pre>\n\n<p>It produces the following ouput (example).</p>\n\n<pre><code>Month | Year | Total\n\nJanuary | 2009 | 2\n</code></pre>\n'}, {'answer_id': 842693, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I had the same problem and after looking around I found this:</p>\n\n<pre><code>SELECT DATENAME(yyyy, date) AS year\nFROM Income\nGROUP BY DATENAME(yyyy, date)\n</code></pre>\n\n<p>It's working great!</p>\n"}, {'answer_id': 861594, 'author': 'GordyII', 'author_id': 68654, 'author_profile': 'https://Stackoverflow.com/users/68654', 'pm_score': 3, 'selected': False, 'text': "<p>How about this?</p>\n\n<pre><code>Select DateName( Month, getDate() ) + ' ' + DateName( Year, getDate() )\n</code></pre>\n"}, {'answer_id': 2107799, 'author': 'Alok Kumar', 'author_id': 255495, 'author_profile': 'https://Stackoverflow.com/users/255495', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, you can use <code>datename(month,intime)</code> to get the month in text.</p>\n'}, {'answer_id': 4244079, 'author': 'don', 'author_id': 515873, 'author_profile': 'https://Stackoverflow.com/users/515873', 'pm_score': 4, 'selected': False, 'text': '<p>Use:</p>\n\n<pre><code>select datepart(mm,getdate())  --to get month value\nselect datename(mm,getdate())  --to get name of month\n</code></pre>\n'}, {'answer_id': 5389842, 'author': 'Matteo', 'author_id': 671015, 'author_profile': 'https://Stackoverflow.com/users/671015', 'pm_score': -1, 'selected': False, 'text': "<p>The following works perfectly! I just used it, try it out.</p>\n\n<pre><code>date_format(date,'%Y-%c')\n</code></pre>\n"}, {'answer_id': 15957013, 'author': 'Ron Smith', 'author_id': 2271803, 'author_profile': 'https://Stackoverflow.com/users/2271803', 'pm_score': 1, 'selected': False, 'text': "<p>Converting the date to the first of the month allows you to Group By and Order By a single attribute, and it's faster in my experience.</p>\n\n<pre><code>declare @mytable table(mydate datetime)\ndeclare @date datetime\nset @date = '19000101'\nwhile @date &lt; getdate() begin\n    insert into @mytable values(@date)\n    set @date = dateadd(day,1,@date)\nend\n\nselect count(*) total_records from @mytable\n\nselect dateadd(month,datediff(month,0,mydate),0) first_of_the_month, count(*) cnt\nfrom @mytable\ngroup by dateadd(month,datediff(month,0,mydate),0)\n</code></pre>\n"}, {'answer_id': 19244174, 'author': 'Lalmuni Singh', 'author_id': 2857980, 'author_profile': 'https://Stackoverflow.com/users/2857980', 'pm_score': 1, 'selected': False, 'text': "<pre><code>---Lalmuni Demos---\ncreate table Users\n(\nuserid int,date_of_birth date\n)\n---insert values---\ninsert into Users values(4,'9/10/1991')\n\nselect DATEDIFF(year,date_of_birth, getdate()) - (CASE WHEN (DATEADD(year, DATEDIFF(year,date_of_birth, getdate()),date_of_birth)) &gt; getdate() THEN 1 ELSE 0 END) as Years, \nMONTH(getdate() - (DATEADD(year, DATEDIFF(year, date_of_birth, getdate()), date_of_birth))) - 1 as Months, \nDAY(getdate() - (DATEADD(year, DATEDIFF(year,date_of_birth, getdate()), date_of_birth))) - 1 as Days,\nfrom users\n</code></pre>\n"}, {'answer_id': 19438293, 'author': 'Gareth Thomas', 'author_id': 1941758, 'author_profile': 'https://Stackoverflow.com/users/1941758', 'pm_score': 2, 'selected': False, 'text': '<pre><code>cast(cast(sq.QuotaDate as date) as varchar(7))\n</code></pre>\n\n<p>gives "2006-04" format</p>\n'}, {'answer_id': 23981171, 'author': 'cyber cyber1621', 'author_id': 1031692, 'author_profile': 'https://Stackoverflow.com/users/1031692', 'pm_score': 3, 'selected': False, 'text': '<p>the best way to do that is with :</p>\n\n<pre><code>dateadd(month,datediff(month,0,*your_date*),0)\n</code></pre>\n\n<p>it will keep your datetime type</p>\n'}, {'answer_id': 27105774, 'author': 'CrimsonKing', 'author_id': 4287441, 'author_profile': 'https://Stackoverflow.com/users/4287441', 'pm_score': 6, 'selected': False, 'text': "<p>Beginning with SQL Server 2012, you can use:</p>\n\n<pre><code>SELECT FORMAT(@date, 'yyyyMM')\n</code></pre>\n"}, {'answer_id': 29506934, 'author': 'Hammad Khan', 'author_id': 777982, 'author_profile': 'https://Stackoverflow.com/users/777982', 'pm_score': 2, 'selected': False, 'text': '<p>The question is about SQL Server 2005, many of the answers here are for later version SQL Server.</p>\n\n<pre><code>select convert (varchar(7), getdate(),20)\n--Typical output 2015-04\n</code></pre>\n\n<p>SQL Server 2005 does not have date function <a href="https://msdn.microsoft.com/en-us/library/bb630352.aspx" rel="nofollow">which was introduced in SQL Server 2008</a> </p>\n'}, {'answer_id': 33643495, 'author': 'khmer angkor', 'author_id': 5549082, 'author_profile': 'https://Stackoverflow.com/users/5549082', 'pm_score': 0, 'selected': False, 'text': '<pre><code>  ,datename(month,(od.SHIP_DATE)) as MONTH_\n</code></pre>\n\n<p>Answer: \nMONTH_\nJanuary\nJanuary\nSeptember\nOctober\nDecember\nOctober\nSeptember</p>\n'}, {'answer_id': 37896317, 'author': 'webbuilder', 'author_id': 1466076, 'author_profile': 'https://Stackoverflow.com/users/1466076', 'pm_score': 4, 'selected': False, 'text': '<p>In SQL server 2012, below can be used</p>\n\n<p>select FORMAT(getdate(), \'MMM yyyy\')</p>\n\n<p>This gives exact "Jun 2016"</p>\n'}, {'answer_id': 42681098, 'author': 'RobertC', 'author_id': 1678020, 'author_profile': 'https://Stackoverflow.com/users/1678020', 'pm_score': 2, 'selected': False, 'text': "<p>returns the full month name, -, full year e.g. <code>March-2017</code></p>\n\n<pre><code>CONCAT(DATENAME(mm, GetDate()), '-', DATEPART(yy, GetDate()))\n</code></pre>\n"}, {'answer_id': 44340913, 'author': 'GanbatSu', 'author_id': 8106226, 'author_profile': 'https://Stackoverflow.com/users/8106226', 'pm_score': 0, 'selected': False, 'text': "<p>It's work great.</p>\n\n<pre><code>DECLARE @pYear VARCHAR(4)\n\nDECLARE @pMonth VARCHAR(2)\n\nDECLARE @pDay VARCHAR(2)\n\nSET @pYear  = RIGHT(CONVERT(CHAR(10), GETDATE(), 101), 4)\n\nSET @pMonth = LEFT(CONVERT(CHAR(10), GETDATE(), 101), 2)\n\nSET @pDay   = SUBSTRING(CONVERT(CHAR(10), GETDATE(), 101), 4,2)\n\nSELECT @pYear,@pMonth,@pDay\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/45535', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1688440/']