Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Yonkouturko
Yak Posting Veteran
59 Posts |
Posted - 2012-12-20 : 21:44:32
|
Can i make a mathematical Expression for two different table..for exampletable1 has fieldsid /description /qtytable2 has fieldsid description /received_qtycan i do this...( (select qty from table1) as purchase_QTY - (minus)(select received_qty from table2) as received_QTY ) as Remaining_QTYis that even possible??? Please Help-----yonkouTurko |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-12-20 : 22:09:54
|
[code]select t1.qty - t2.received_qtyfrom table1 t1 inner join table2 t2 on t1.id = t2.id[/code]use LEFT JOIN if you may not have the corresponding record in table2 KH[spoiler]Time is always against us[/spoiler] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-12-21 : 00:43:49
|
[code]SELECT id,description,SUM(qty) - SUM(received_qty) AS RemainingFROM(SELECT id,description,qty,CAST(0 AS int) AS receivedFROM table1UNION ALLSELECT id,description,0,received_qtyFROM table2)tGROUP BY id,description[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|