Reputation: 277
I am trying to create a column that is the total value of column A,B,C,D,E.
select,[TVIncome] a
,[XIncome] b
,[ZIncome] c
,[DINCOME] d
,[OIncome] e
sum(a,b,c,d,e) as total
The error I get when doing the above sum is :"The sum function requires 1 argument(s)."
The total above does not work. Also, if I just include the the proper names, XIncome and the rest,it still does not work. How do I do it?
Upvotes: 0
Views: 4402
Reputation: 63152
SUM()
adds each value in a column, to give a single value
+
adds each value in two columns together to give a column
It sounds like you are after a + b + c + d + e AS total
,
or possibly SUM(a + b + c + d + e) AS total
if you are after 1 value
Upvotes: 2
Reputation: 7740
Assuming you want a sum for those columns for each row
SELECT (TVIncome + XIncome + ZIncome + DIncome + OIncome) as TotalIncome
FROM Table
If you want a sum of sums, which will equal one row:
SELECT SUM(TVIncome + XIncome + ZIncome + DIncome + OIncome) as TotalIncome
FROM Table
Upvotes: 2