• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1228
  • Last Modified:

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.
0
jfsedlar3rd
Asked:
jfsedlar3rd
2 Solutions
 
derekkrommCommented:
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
 
LowfatspreadCommented:
select coalesce(column1,0)+coalesce(column2,0) + ....coalesce(column12,0) as Withold,empid
 from yourtable

 
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now