sql server - aging structure using sql query -


i have table structure following

tno date        netamt  chq cash    party --------------------------------------------- t1  01/04/2016  100     10  0       test1 t2  15/04/2016  50      0   0       test2 t3  18/04/2016  100     100 0       test3 

now want make sql query give me aging report of transactions lying outstanding in slabs.

i want see result in following format

party   0-3 days    4-6 days    7-15 days ---------------------------------------------    test1       0           0           90 test2       0           50          0 test3       0           0           0 

try this

select  party,         sum(case when datediff(day,[date],getdate()) between 0 , 3  (netamt - chq) else 0 end) [0_3_days],         sum(case when datediff(day,[date],getdate()) between 4 , 6  (netamt - chq) else 0 end) [4_6_days],         sum(case when datediff(day,[date],getdate()) between 7 , 15 (netamt - chq) else 0 end) [7_15_days],    table1 group party 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -