Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
galbrecht
Starting Member
17 Posts |
Posted - 2009-12-07 : 16:34:15
|
| Hi I have a table that holds all our service desk calls. I would like to be able to extract the total number of calls logged pre year and month as well as total calls closed per year and month. and example of the table is as folows.requestid, Requestdate, requestclosedate12, 01/01/2009, 10/01/200913, 02/01/200914, 01/01/2009, 15, 01/01/2009, 20/01/200916, 03/01/2009, 21/01/200917, 04/01/2009, 21/01/2009Could somebody please help me outThanksGreg |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-07 : 17:19:41
|
Maybe this?Count yearly -select datepart(year,Requestdate),count (requestid) from <table>group by datepart(year,Requestdate) Count monthly -select datename(month,Requestdate),count (requestid) from <table>group by datename(month,Requestdate) |
 |
|
|
galbrecht
Starting Member
17 Posts |
Posted - 2009-12-07 : 17:31:28
|
| Thanks for the reply,My appologies - I never said what I wanted correctly. I would like to have one query that gives me the result as follows: Moth, total by requestdate and total by requestclosedate.Month, Requestdate, RequestclosedateJanuary, 10, 9February, 5, 7March, 20, 7Thanks |
 |
|
|
Kumar_Anil
Yak Posting Veteran
68 Posts |
Posted - 2009-12-07 : 18:18:21
|
| Hello,I dont have sql server installed to work with what I wrote in here but please try this & let me know.regards,Anil.Select b.ClosedMonth, b.MonthlyTotal, sum(a.MonthlyTotal) AS CumulativeTotalsThruYearfrom(select sum(requestid) as MonthlyTotal, datepart(month, requestclosedate) as ClosedMonthfrom table group by datepart(month, requestclosedate))bcross join (select sum(requestid) as MonthlyTotal, datepart(month, requestclosedate) as ClosedMonthfrom table group by datepart(month, requestclosedate))awhere a.MonthlyTotal < b.MonthlyTotalgroup by b.ClosedMonth, b.MonthlyTotal |
 |
|
|
|
|
|
|
|