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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Please Help!!! Maybe Simple Query Problem

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 Jan

The output should be as follows:

Month Closed Overdue
Oct 500 10
Sept 400 35
Aug 543 5
July 624 9

At the moment it just summarises the total for Closed and Overdue and displys the values in every row like this

Month Closed Overdue
Oct 1000 50
Sept 1000 50
Aug 1000 50
July 1000 50

Please help!!! I really need to resolve this query


select 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?

Go to Top of Page

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 Overdue
from tblservicerequest servicerequest
where timeclosed between '01-Jan-2008' and getdate()
GROUP BY DATEADD(mm,DATEDIFF(mm,0,timeclosed),0)
)t
[/code]
Go to Top of Page
   

- Advertisement -