I need help from DBA's and from those who got a better knowledge of SQL SERVER.
I need to produce an aging of accounts. Below is my query and its result:
- select SUM(e.TotalPremium) AS [SOLD POLICY],
- CASE
- WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 30 THEN '30 Days'
- WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 60 THEN '60 Days'
- WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 90 THEN '90 Days'
- ELSE 'Above 90 days'
- END as AGING
- from tblMotorInsurance_eCI e
- where e.AgentID='16-113-01' and e.Remarks <> 'Cancel' and e.IsPaid = 'false'
- group by e.DateIssued
As you can see from the result, I need to group them according to aging of accounts. Any help is really appreciated.