Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query with equi join, need to have both side value

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2014-10-01 : 14:14:19
I have table1 with fin_number,legacy_charge

table2 with fin_number,new_charge

I want to add both values based on fin_number, no values to be missed.


Select coalesce(t1.fin_number,t2.fin_number) as finance_number,(t1.legacy_charge + t2.New_charge) as Current_charge from
table1 t1 equijoin table2 t2 on(t1.fin_number = t2.fin_number)

if t2.fin_number not available in table1, still i want that info to appear.
what would be the best way to add the charge1 and charge2. using fin_number.

Thanks a lot for the helpful info.




ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-10-01 : 15:19:21
You're very close:

Select coalesce(t1.fin_number,t2.fin_number) as finance_number, (isnull(t1.legacy_charge, 0) + isnull(t2.New_charge, 0)) as Current_charge
from table1 t1
full outer join table2 t2 on(t1.fin_number = t2.fin_number)
Go to Top of Page
   

- Advertisement -