Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    24

    Unanswered: How to sum column in a single row

    Hi, (NOTE: Title should read "How to sum columns in a single row")

    I have a temp table in a stored proc:

    CREATE TABLE #tempMETRICS
    (
    metric VARCHAR(100),
    domicileA int NULL,
    domicileB int NULL,
    domicileC int NULL
    )

    which I fill with data from various sources.

    At the end of the s.p., I do a simple select:

    SELECT Metric = metric,
    A = domicileA,
    B = domicileB,
    C = domicileC
    FROM #tempMETRICS

    What I would like to do is have the SELECT include a fifth parameter that
    is the sum of domicileA, domicileB, and domicileC for each row.

    Thanks in Advance,
    chasse
    Last edited by chassemerrill; 09-10-09 at 18:52.

  2. #2
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    Simple SQL question.
    Code:
    SELECT  Metric = metric,
            A = domicileA,
            B = domicileB,
            C = domicileC,
            Total = domicileA + domicileB + domicileC
        FROM #tempMETRICS
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

  3. #3
    Join Date
    Aug 2008
    Posts
    24
    Thanks, I thought I had tried that, but must have had some other typo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •