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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum 2 variables in a stored procedure, how ?

Status
Not open for further replies.

Webkins

Programmer
Dec 11, 2008
118
US
I am having troubles to sum these 2 variables into one. I have tried many combinations of the code below but nothing seems to work...

--Query for data
SET @raw_gallons = (SELECT raw_gallons FROM impregnation.dbo.tank_raw)
SET @day_gallons = (SELECT day_gallons FROM impregnation.dbo.tank_day)

SET @Combined_Levels = (select SUM(@raw_gallons + @day_gallons))
SET @Combined_Levels = SUM(@raw_gallons + @day_gallons)
SET @Combined_Levels = (@raw_gallons + @day_gallons)

Thanks to all for your suggestions and help.
 
That's not going to work the way you think it is, unless by some freaky chance you only have 1 row in each of those tables, though it will probably still give you ayntax error)

You probably want something like:
Code:
Select tr.raw_gallons + td.day_gallons
FROM tank_raw tr
LEFT JOIN tank_day td ON
   tr.tankID = td.tankID
Order by tankID

Lodlaiden

You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top