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
 total per quarter and year
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eugz
Posting Yak Master

196 Posts

Posted - 10/08/2012 :  18:47:44  Show Profile  Reply with Quote
Hi All.

Here I count request per month

SELECT
 MONTH(ReceivedDate) [Month]
,DATEPART(QQ,ReceivedDate) [Quarter]
,YEAR(ReceivedDate) [Year]
,Case DATEPART(QQ,ReceivedDate) 
	When 1 Then 'I Quarter'
	When 2 Then 'II Quarter'
	When 3 Then 'III Quarter'
	When 4 Then 'IV Quarter'
End [QuarterName]
,Case Month(ReceivedDate) 
	When 1 Then 'January'
	When 2 Then 'February'
	When 3 Then 'March'
	When 4 Then 'April'
	When 5 Then 'May'
	When 6 Then 'June'
	When 7 Then 'July'
	When 8 Then 'August'
	When 9 Then 'September'
	When 10 Then 'October'
	When 11 Then 'November'
	When 12 Then 'December'
End [MonthName]
,count(Test_No) Test_No
FROM   dbo.Request
GROUP BY MONTH(ReceivedDate), DATEPART(QQ, ReceivedDate), YEAR(ReceivedDate)
ORDER BY YEAR(ReceivedDate), DATEPART(QQ, ReceivedDate), MONTH(ReceivedDate)


How to calculate request per quarter and year?

Thanks.

Edited by - eugz on 10/08/2012 18:57:05

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/08/2012 :  19:41:05  Show Profile  Reply with Quote
grouping by quarter


SELECT
DATEPART(QQ,ReceivedDate) [Quarter]
,YEAR(ReceivedDate) [Year]
,Case DATEPART(QQ,ReceivedDate) 
	When 1 Then 'I Quarter'
	When 2 Then 'II Quarter'
	When 3 Then 'III Quarter'
	When 4 Then 'IV Quarter'
End [QuarterName]
,count(Test_No) Test_No
FROM   dbo.Request
GROUP BY DATEPART(QQ, ReceivedDate), YEAR(ReceivedDate)
ORDER BY YEAR(ReceivedDate), DATEPART(QQ, ReceivedDate)


grouping by year


SELECT
 YEAR(ReceivedDate) [Year]
,count(Test_No) Test_No
FROM   dbo.Request
GROUP BY YEAR(ReceivedDate)
ORDER BY YEAR(ReceivedDate)


grouping by all side by side


SELECT
 MONTH(ReceivedDate) [Month]
,DATEPART(QQ,ReceivedDate) [Quarter]
,YEAR(ReceivedDate) [Year]
,Case DATEPART(QQ,ReceivedDate) 
	When 1 Then 'I Quarter'
	When 2 Then 'II Quarter'
	When 3 Then 'III Quarter'
	When 4 Then 'IV Quarter'
End [QuarterName]
,Case Month(ReceivedDate) 
	When 1 Then 'January'
	When 2 Then 'February'
	When 3 Then 'March'
	When 4 Then 'April'
	When 5 Then 'May'
	When 6 Then 'June'
	When 7 Then 'July'
	When 8 Then 'August'
	When 9 Then 'September'
	When 10 Then 'October'
	When 11 Then 'November'
	When 12 Then 'December'
End [MonthName]
,count(Test_No) Test_No
FROM   dbo.Request
GROUP BY GROUPING SETS ((MONTH(ReceivedDate)), (DATEPART(QQ, ReceivedDate)), (YEAR(ReceivedDate)))
ORDER BY YEAR(ReceivedDate), DATEPART(QQ, ReceivedDate), MONTH(ReceivedDate)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.05 seconds. Powered By: Snitz Forums 2000