SQL Multiple field record sum.

I am writing a transact SQL query on a table that has multiple fields for employee withholdings(12 fields to be exact) I am looking for a way to aggregate those fields into one SUM on a per record(employee) basis.
jfsedlar3rdAsked:
Who is Participating?
 
derekkrommConnect With a Mentor Commented:
Are you trying to sum all 12 fields for each employee?

select PrimaryKey, sum(field1 + field2 + field3 + ...)
from employeetable
group by PrimaryKey

If there's just 1 field that needs to be SUMed, but you need all the fields:

select PrimaryKey, field1, field2, ..., sum(addfield)
from employeetable
group by PrimaryKey, field1, field2, ...
0
 
LowfatspreadConnect With a Mentor Commented:
select coalesce(column1,0)+coalesce(column2,0) + ....coalesce(column12,0) as Withold,empid
 from yourtable

 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.