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 |
|
mchute
Starting Member
4 Posts |
Posted - 2008-11-08 : 07:51:39
|
| I am running the following query not sure if its correct but need to summarise a list of closed calls / overdue calls since JanThe output should be as follows:Month Closed OverdueOct 500 10Sept 400 35Aug 543 5July 624 9At the moment it just summarises the total for Closed and Overdue and displys the values in every row like thisMonth Closed OverdueOct 1000 50Sept 1000 50Aug 1000 50July 1000 50Please help!!! I really need to resolve this queryselect DATENAME(mm,timeclosed), (select Count(1) from tblservicerequest where timeclosed between '01-Jan-2008' and getdate() AND status = 6 ) [Total], (select Count(1) from tblservicerequest where timeclosed between '01-Jan-2008' and getdate() AND status in (4) ) [Breach] from tblservicerequest servicerequest GROUP BY DATENAME(mm,timeclosed) , DATEPART(mm,timeclosed) |
|
|
Jatsie
Starting Member
15 Posts |
Posted - 2008-11-09 : 02:45:44
|
| Is this PL/SQL or T-SQL? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-09 : 04:20:44
|
| [code]select DATENAME(mm,timeclosed),Closed,Overdue FROM(select DATEADD(mm,DATEDIFF(mm,0,timeclosed),0) AS timeclosed,SUM(CASE WHEN status = 6 THEN 1 ELSE 0 END) AS Closed,SUM(CASE WHEN status = 4 THEN 1 ELSE 0 END) AS Overduefrom tblservicerequest servicerequest where timeclosed between '01-Jan-2008' and getdate()GROUP BY DATEADD(mm,DATEDIFF(mm,0,timeclosed),0))t[/code] |
 |
|
|
|
|
|
|
|