0

I have two tables with same column name I have to add the oprId column values for some specific condition on both tables.

Table 1

something  oprId

abc          1
qwe          2

Table 2

something  oprId

abc          2
qwe          5 

Result should be

oprId
3
7
4
  • I think you have left out the important part of the question. Where does 3 and 7 come from? Commented Oct 20, 2011 at 17:36
  • it should be the sum of oprId 1+2 and 2+5 Commented Oct 20, 2011 at 17:37
  • Ok. So you join xyz to abc and ghj to qwe? Are those values parameters to the query? Commented Oct 20, 2011 at 17:39
  • sorry, I have edited the question now Commented Oct 20, 2011 at 17:40

2 Answers 2

1
declare @T1 table (something varchar(3), oprId int)
declare @T2 table (something varchar(3), oprId int)

insert into @T1 values ('abc', 1),('qwe', 2)
insert into @T2 values ('abc', 2),('qwe', 5)

select T1.oprId+T2.oprId as oprId
from @T1 as T1
  inner join @T2 as T2
    on T1.something = T2.something

Result:

oprId
------
3
7
Sign up to request clarification or add additional context in comments.

Comments

0
SELECT ISNULL(A.something,B.something) Something,
       ISNULL(A.oprId,0)ÍSNULL(B.oprId,0) oprId
FROM Table1 A
FULL JOIN Table2 B
ON A.something = B.something

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.