471,075 Members | 1,184 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

Subtracting two columns from diff tables

Hi all,

I encountered this small problem

I have two tables A and B with two columns 1 and 2 each, I would like
the first column of each table when match the first in the second table
is to subtract the second column

so the result would look as follows

Column 1 | Columnn 2
where A1=B1 | A2-B2

Now this is no problem so far ..

But if there was no corresponding value in column 1 in either tables ..
i.e. field A1 doesnt exist in Table B column 1, IT SHALL DO A2 - 0; or
0-B2 ..

NOW How can that be achieved ?

Thanks all for your help

Nov 29 '05 #1
3 14616
MC
Does this work for you?

select
isnull(A.A2,0) - isnull(B.B2,0) as Diff
from
tableA A
full outer join tableB B on A.A1 = B.B1
MC
<al******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi all,

I encountered this small problem

I have two tables A and B with two columns 1 and 2 each, I would like
the first column of each table when match the first in the second table
is to subtract the second column

so the result would look as follows

Column 1 | Columnn 2
where A1=B1 | A2-B2

Now this is no problem so far ..

But if there was no corresponding value in column 1 in either tables ..
i.e. field A1 doesnt exist in Table B column 1, IT SHALL DO A2 - 0; or
0-B2 ..

NOW How can that be achieved ?

Thanks all for your help

Nov 29 '05 #2
Hi,

Select ISNULL(Table1.col2,0) - ISNULL(Table2.col2,0)
FROm Table1
FULL OUTER JOIN Table2
ON Table1.Col1 = Table2.Col1

HTH, Jens Suessmeyer.

Nov 29 '05 #3
Hi all

thanks alot jens and mc i could easily figure it out.
regards

Nov 30 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert Schoenert | last post: by
13 posts views Thread by scorpion53061 | last post: by
9 posts views Thread by Mike Fellows | last post: by
6 posts views Thread by Igor Shevchenko | last post: by
5 posts views Thread by explode | last post: by
1 post views Thread by Lennart | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.