Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Select d.Transaction_No,d.Amount_Debit,d.Debit_Date,d.Total_Amount_Debit,c.Transaction_No,c.Amount_Credit,c.Credit_Date,c.Total_Amount_Credit from Account_Debit d left join Account_Credit c on c.Account_No=d.Account_No and  d.Account_No='1234-5';


TransactionNo
1	    6565	2013-01-04	883441	1	54	2013-01-04	54
1	    6565	2013-01-04	883441	2	54	2013-01-04	108
1	    6565	2013-01-04	883441	3	6565	2013-01-04	6673
1	    6565	2013-01-04	883441	4	6756	2013-01-04	13429
2	    65654	2013-01-04	949095	1	54	2013-01-04	54
2	    65654	2013-01-04	949095	2	54	2013-01-04	108
2	    65654	2013-01-04	949095	3	6565	2013-01-04	6673
2	    65654	2013-01-04	949095	4	6756	2013-01-04	13429
3	    65567	2013-01-04	1014662	1	54	2013-01-04	54
3	    65567	2013-01-04	1014662	2	54	2013-01-04	108
3	    65567	2013-01-04	1014662	3	6565	2013-01-04	6673
3	    65567	2013-01-04	1014662	4	6756	2013-01-04	13429
4	    6564	2013-01-04	1021226	1	54	2013-01-04	54
4	    6564	2013-01-04	1021226	2	54	2013-01-04	108
4	    6564	2013-01-04	1021226	3	6565	2013-01-04	6673
4	    6564	2013-01-04	1021226	4	6756	2013-01-04	13429
Posted
Comments
Aarti Meswania 7-Jan-13 2:12am    
what output you want?
zeshanazam 7-Jan-13 2:13am    
each transaction should appear only one time...
e.g
Transaction no
1
2
3
4
Aarti Meswania 7-Jan-13 2:15am    
you mean Account_Debit and account credit same transaction nos should together?
you want output like below?
1 6565 2013-01-04 883441 1 54 2013-01-04 54
2 65654 2013-01-04 949095 2 54 2013-01-04 108
3 65567 2013-01-04 1014662 3 6565 2013-01-04 6673
4 6564 2013-01-04 1021226 4 6756 2013-01-04 13429
zeshanazam 7-Jan-13 2:16am    
Exactly like this :)

1 solution

you have missing to join transaction nos. use below query
SQL
Select d.Transaction_No,d.Amount_Debit,d.Debit_Date,d.Total_Amount_Debit,c.Transaction_No,c.Amount_Credit,c.Credit_Date,c.Total_Amount_Credit 
from Account_Debit d 
left join Account_Credit c on c.Account_No=d.Account_No and d.Transaction_No=c.Transaction_No
where d.Account_No='1234-5';

Happy Coding!
:)
 
Share this answer
 
Comments
zeshanazam 7-Jan-13 2:21am    
what if i do not want to include transaction no... ??
Aarti Meswania 7-Jan-13 2:23am    
it will give you desired output

you can compare that condition inside where clause also

Select d.Transaction_No,d.Amount_Debit,d.Debit_Date,d.Total_Amount_Debit,c.Transaction_No,c.Amount_Credit,c.Credit_Date,c.Total_Amount_Credit
from Account_Debit d
left join Account_Credit c on c.Account_No=d.Account_No
where d.Account_No='1234-5' and d.Transaction_No=c.Transaction_No;

zeshanazam 7-Jan-13 2:24am    
when i exclude transaction column, it again produce repeating results..
Select d.Amount_Debit,d.Debit_Date,d.Total_Amount_Debit,c.Amount_Credit,c.Credit_Date,c.Total_Amount_Credit
from Account_Debit d
left join Account_Credit c on c.Account_No=d.Account_No
where d.Account_No='1234-5';
Aarti Meswania 7-Jan-13 2:27am    
do not exclude it because you want results that have same account nos and transaction nos also.

so, use transaction no. condition in left join as I do in my answer :)
zeshanazam 7-Jan-13 2:29am    
thanx, i want to add last values of 2nd and 4th column and result in last column, how to access column of crystal reports in c#

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