0

I need to get result from Existing Table and my current result is like

Code    Name            Branch  Dr          Cr          Net                 
1001    Closing Stock   UP      150000      195000      -45000                  
1001    Closing Stock   DL      159.74      0           159.74                  
1001    Closing Stock   CH      0           24.37       -24.37                  
1002    IGST Payable    UP      0           135.37      -135.37                 
1002    IGST Payable    DL      0           200         -200                    
1002    IGST Payable    CH      200         0           200                 
1003    Sundry Debtors  UP      15767000    0           15767000                    
1003    Sundry Debtors  DL      0           181716      -181716                 

Note :

  • If Branches Increase then Branch wise (Debit,Credit,Net) Fields should be Create automatically.

And Result should be like this

Code   Name UPDr    UPCr    UPNet   CHDr  CHCr  CHNet  DLDr   DLCr  DLNet
1001   Stk  1500    1950    -450    0     24.37 -24.37 159    0     159.74
1002   IGST 0       135.37  -135    200   0     200    0      181   -181
1003   Sund 157     0       157     159   0     159    200    0     200

Please help for the same.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Om Joshi
  • 1
  • 2
  • What is the SQL statement you tried ("my current result"), what is your issue in achieving the expected result? – Sandra Rossi Mar 29 '22 at 11:54
  • learn what is [pivoting](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) and how to implement it, also you didn't specify your SQL dialect – Suncatcher Mar 29 '22 at 12:06
  • You have some problem with dimensions - why does 150000 turns into 1500 and at the same time 159.74 turns into 159 after aggregation? The solution might be to use LEFT JOIN with some IFNULL-like predicate, but you really do need to specify what exact tool/SQL dialect you are working with. – shomeax Mar 30 '22 at 13:53

0 Answers0