Jes Sie

Jes Sie

  • 663
  • 1.2k
  • 282k

Aging of Accounts in SQL SERVER

May 30 2018 1:31 AM
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:
  1. select SUM(e.TotalPremium) AS [SOLD POLICY],   
  2.     CASE  
  3.         WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 30 THEN '30 Days'  
  4.         WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 60 THEN '60 Days'  
  5.         WHEN DATEDIFF(D, e.DateIssued, getdate()) <= 90 THEN '90 Days'  
  6.         ELSE 'Above 90 days'  
  7.     END as AGING  
  8. from tblMotorInsurance_eCI e   
  9. where e.AgentID='16-113-01' and e.Remarks <> 'Cancel' and e.IsPaid = 'false'  
  10. 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. 

Answers (2)