SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dr223
Constraint Violating Yak Guru

361 Posts

Posted - 06/28/2012 :  05:25:27  Show Profile  Reply with Quote
Hi,

I have the following command;

SELECT Month(R.date)as Month, YEAR(R.date) as Year, COUNT(*) as Total
FROM dbo.aspnet_cprdContacts
GROUP BY MONTH(R.date),YEAR(R.date)


Result:

Month Year Total

3 2012 62
4 2012 146
5 2012 81

I want the result to be;

Month Year Total

March 2012 62
April 2012 146
May 2012 81

Convert month number to month name..

Thank you


Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3442 Posts

Posted - 06/28/2012 :  05:30:27  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
either join to a MonthDescription table on the month number or format it in the display layer.

Or use a CASE statement... but that one is a hack.

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

dr223
Constraint Violating Yak Guru

361 Posts

Posted - 06/28/2012 :  05:32:10  Show Profile  Reply with Quote
I dont want to link to MonthDescription table option - want to code it within the select statement
Go to Top of Page

Transact Charlie
Flowing Fount of Yak Knowledge

United Kingdom
3442 Posts

Posted - 06/28/2012 :  05:54:05  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
Sigh...

DECLARE @date DATE = GETDATE()

SELECT CASE MONTH(@date)
	WHEN 1 THEN 'Jan'
	WHEN 2 THEN 'Feb'
	WHEN 3 THEN 'Mar'
	WHEN 4 THEN 'Apr'
	WHEN 5 THEN 'May'
	WHEN 6 THEN 'Jun'
	WHEN 7 THEN 'Jul'
	WHEN 8 THEN 'Aug'
	WHEN 9 THEN 'Sep'
	WHEN 10 THEN 'Oct'
	WHEN 11 THEN 'Nov'
	WHEN 12 THEN 'Dec'
	END


Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

waterduck
Aged Yak Warrior

Malaysia
791 Posts

Posted - 06/29/2012 :  03:17:41  Show Profile  Reply with Quote
SELECT DATENAME(m, R.date)as Month, YEAR(R.date) as Year, COUNT(*) as Total
FROM dbo.aspnet_cprdContacts
GROUP BY DATENAME(m, R.date),YEAR(R.date)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000