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

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

Yonkouturko
Yak Posting Veteran

Philippines
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

-----
yonkouTurko

khtan
In (Som, Ni, Yak)

Singapore
17682 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 t1.id = t2.id


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


KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

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

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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