Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query Complexities
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

59 Posts

Posted - 12/20/2012 :  21:44:32  Show Profile  Reply with Quote
Can i make a mathematical Expression for two different table..
for example
table1 has fields
id /description /qty
table2 has fields
id description /received_qty

can i do this...
( (select qty from table1) as purchase_QTY
- (minus)
(select received_qty from table2) as received_QTY ) as Remaining_QTY

is that even possible??? Please Help


In (Som, Ni, Yak)

17689 Posts

Posted - 12/20/2012 :  22:09:54  Show Profile  Reply with Quote
select t1.qty - t2.received_qty
from   table1 t1 inner join table2 t2 on =

use LEFT JOIN if you may not have the corresponding record in table2

Time is always against us

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/21/2012 :  00:43:49  Show Profile  Reply with Quote

SELECT id,description,SUM(qty) - SUM(received_qty) AS Remaining
SELECT id,description,qty,CAST(0 AS int) AS received
FROM table1
SELECT id,description,0,received_qty
FROM table2
GROUP BY id,description

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000