Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have two table like
1 table
Date         DistId BranchID CreditAmount
01/01/2016   101       1        5000
02/01/2016   101       1        5000
01/02/2016   101       1        6000
01/01/2016   101       2        700
01/01/2016   102       1        400


2 table
Date        DistId  BranchId  DebitAmount
01/01/2016   101       1        6000
02/01/2016   101       1        7000
01/02/2016   101       1        9000
01/01/2016   101       2        500
01/01/2016   102       1        400


i want to like as under below

Date        DistId BranchId  CreditAmount DebitAmount Balance AmountType
01/01/2016  101     1           10000      13000       3000      Dr
01/02/2016  101     1           16000      22000       6000      Dr

as 1/12/2016

What I have tried:

SQL
select a.Date, a.DistID, a.BranchId, sum(CreditAmount)
from t a;
Posted
Updated 19-Mar-16 6:01am
v2
Comments
RickZeeland 25-Mar-16 14:10pm    
And ? have you fallen asleep ? did you try my solution ?

1 solution

SELECT a.Date, a.DistID, a.BranchId, SUM(a.CreditAmount) AS CreditAmount, NULL AS DebitAmount
FROM a
GROUP BY a.Date, a.DistID, a.BranchId
UNION
SELECT b.Date, b.DistID, b.BranchId, NULL, SUM(b.DebitAmount) 
FROM b
GROUP BY b.Date, b.DistID, b.BranchId
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900