Click here to Skip to main content
15,891,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends
i have tow same table with tow columns(Code , Cost)
and i wanna subtract this tables

table1 table2
---------------- ----------------
code | cost code | cost
------------- -------------
1 | 100 1 | 50
2 | 200 2 | 100
3 | 300 3 | 200
4 | 400


result = table1 - table2
----------------
code | cost
-------------
1 | 50
2 | 100
3 | 100
4 | 400


please guide me ...
Posted

1 solution

you can use left join for this. example
SQL
select code, a.cost - isnull(b.cost,0) from table1 a 
left join table2 b on a.code = b.code
 
Share this answer
 
Comments
vahid_erad 19-Sep-11 4:24am    
How do i for create temp-table ??
vahid_erad 19-Sep-11 4:25am    
how do this : isnull(b.cost,0) ?
Om Prakash Pant 19-Sep-11 4:41am    
you said you have 2 different tables with same schema and you want to subtract the cost. correct?

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