SQL Multiple field record sum.

Posted on 2007-07-23
Last Modified: 2012-05-05
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.
Question by:jfsedlar3rd
    LVL 15

    Accepted Solution

    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, ...
    LVL 50

    Assisted Solution

    select coalesce(column1,0)+coalesce(column2,0) + ....coalesce(column12,0) as Withold,empid
     from yourtable


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now