Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have table1 with fin_number,legacy_chargetable2 with fin_number,new_chargeI 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)