Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

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


Report this thread to moderator Post Follow-up to this message
Old Post
alomrani@gmail.com
11-29-05 08:23 AM


Re: Subtracting two columns from diff tables
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
<alomrani@gmail.com> wrote in message
news:1133252899.750115.34110@o13g2000cwo.googlegroups.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
>



Report this thread to moderator Post Follow-up to this message
Old Post
MC
11-29-05 08:23 AM


Re: Subtracting two columns from diff tables
Hi,

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

HTH, Jens Suessmeyer.


Report this thread to moderator Post Follow-up to this message
Old Post
Jens
11-29-05 08:23 AM


Re: Subtracting two columns from diff tables
Hi all

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


regards


Report this thread to moderator Post Follow-up to this message
Old Post
alomrani@gmail.com
11-30-05 08:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 03:56 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006