I have a crosstabl query that works great summing all records depending on a certain record status [Active, Ended etc etc]
Select
c.ReferralName,
Sum((d.CaseStatusName) = 'Active') As Active,
Sum((d.CaseStatusName) = 'Completed') As Completed,
Sum((d.CaseStatusName) = 'Submitted') As Submitted,
Count(b.CaseID) As Total,
Sum(b.LeadCost) As Cost
From
tblcontacts a Inner Join
tblcases b On a.ContactID = b.ContactID Inner Join
tblreferral c On c.RefferalID = a.ContactReferrelSource Inner Join
tblcasestatus d On d.CaseStatusID = b.CaseStatusName
Group By
c.ReferralName With Rollup
This works great but I now want to also run a query that replaces the Sum of d.CaseStatusName with Sum of b.LeadCost but cannot find a way to achieve it!
I think what I need is to have Sum of b.LeadCost if d.CaseStatusName=’Active’, etc etc
Any help much appreciated.
1 Answer