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)
 reconciliation of table and report

Author  Topic 

Ratz03
Starting Member

27 Posts

Posted - 2014-10-07 : 18:09:28
hi experts,

i am new to sql server development. I have to build reconciliation query and report from one table to another. See sample problem with table and report output needed.

please help me with the query or stored procedure

table 1

pk name age salary
1 abc 7 98
2 asd 2 56
3 xyz 3 10

table 2
pk name age salary
1 abc 1 19
2 asd 2 87
3 xyz 4 987

Report
name age salary delta
table 1 table 2 table 1 table 2 table 1 table 2
abc abc 7 1 98 19 80

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-10-07 : 18:40:36
Why is 'abc' included in the results but not the others?



No amount of belief makes something a fact. -James Randi
Go to Top of Page

Ratz03
Starting Member

27 Posts

Posted - 2014-10-08 : 03:51:49
quote:
Originally posted by Bustaz Kool

Why is 'abc' included in the results but not the others?



No amount of belief makes something a fact. -James Randi



all rows need to come up, including asd and xyz.
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-10-08 : 11:35:55
[code]select t1.name, t2.name, t1.age, t2.age, t1.salary, t2.salary, t1.salary - t2.salary Delta
from table t1
inner join
table2 t2
on t1.name = t2.name -- I'm guessing that the linkage is on name instead of id but you'd know better...[/code]



No amount of belief makes something a fact. -James Randi
Go to Top of Page
   

- Advertisement -