Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure Help

Status
Not open for further replies.

excalibur78

IS-IT--Management
Jan 3, 2001
66
US
I'm trying to get 2 selects to do simple math operations like add and subtract like:

SELECT Sum([DatatecConcentrators]) FROM [Inventory Tracking] -
SELECT Sum([Quantity]) FROM [Products] WHERE [Item Name] = 'Concentrators'

Where the top select return say 100 and the bottom returns 75 then it returns 25 as the result.

Thanks ahead of time.


David
 
Code:
select
(SELECT Sum([DatatecConcentrators]) 
   FROM [Inventory Tracking] -
SELECT Sum([Quantity]) 
   FROM [Products] 
 WHERE [Item Name] = 'Concentrators') as suitableName
 
Code:
select
(SELECT Sum([DatatecConcentrators]) 
   FROM [Inventory Tracking]) -
(SELECT Sum([Quantity]) 
   FROM [Products] 
 WHERE [Item Name] = 'Concentrators') as suitableName
 
Thanks that worked now 1 other thing fast.
How can I do a select top x from .... and use that result from the last select as x in this other select? Can't seem to figure out how to do it myself =(


Thanks a million.
 
Do you mean something like this (untested by me):

select
(SELECT Sum([DatatecConcentrators])
FROM [Inventory Tracking]) -
(SELECT Sum(select top 10 [Quantity] from [products] as prod)
FROM prod
WHERE [Item Name] = 'Concentrators') as suitableName

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top