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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SUM fields in same row?

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-09-19 : 11:16:14
Hi,

The only SUM samples I've seen just do SUM over a column. But I need to add up fields within a row.

ie: select SUM(a, b, c) from x

How would this be done?

Thanks!

--PhB

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-19 : 11:17:14
SELECT Col1, SUM(a + b + c)
FROM Table1
GROUP BY Col1

SELECT Col1, a + b + c AS ColZ
FROM Table1


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-09-19 : 11:19:51
Silly me, I just thought of that.

Thanks!

--PhB
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-09-19 : 11:54:42
Peter handles all of the tough questions here at SQL Team



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-20 : 03:19:25
quote:
Originally posted by Peso

SELECT Col1, SUM(a + b + c)
FROM Table1
GROUP BY Col1

SELECT Col1, a + b + c AS ColZ
FROM Table1


E 12°55'05.25"
N 56°04'39.16"



Dont forget NULLs

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -