Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:53:49+00:00 2026-06-04T08:53:49+00:00

I have a table like: col1 col2 col3 total 3 5 6 7 8

  • 0

I have a table like:

col1 col2 col3 total
3    5    6
7    8    null
...

I want the total column to the sum of col1, col2, col3 for each for. So in the case, total should be:

col1 col2 col3 total
3    5    6    14
7    8    null 15
...

What is the quickest to up the entire total column for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:53:50+00:00Added an answer on June 4, 2026 at 8:53 am
    select col1, col2, col3, 
           isnull(col1,0) + isnull(col2,0) + isnull(col3,0) as total
    from tableName
    

    If you want that column to actually form part of the table, your best bet is to make it a computed column. This stops it going out of sync with the rest of the row, while still allowing you to treat it like any other column in a select statement.

    A create table statement that will do this:

    CREATE TABLE [dbo].[tableName](
        [col1] [int] NULL,
        [col2] [int] NULL,
        [col3] [int] NULL,
        [total]  AS ((isnull([col1],0)+isnull([col2],0))+isnull([col3],0))
    )
    

    Alternatively, in SSMS just goto your table designer, select the total column, and paste the expression isnull([col1],0)+isnull([col2],0))+isnull([col3],0) into the box titled computed column specification > formula

    Finally, if you really want to just backfill the total column in the table (Dont! Its a bad bad idea. Your data will become out of sync later when somebody updates col1,2 or 3 and forgets to update total) just use an update

    UPDATE tableName
    SET total = isnull([col1],0)+isnull([col2],0))+isnull([col3],0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have a table like this: col1 col2 col3 row1 1 null
I have a table like Table1: col1 col2 col3 and have an index over
I have a table like below: COL1 | COL2 | COL3 ______________________ ITEM1 |
I have a table which looks like Col1 col2 col3 col4 col5 1 5
I have a table which looks like Col1 col2 col3 col4 col5 1 5
I have a table like this Table1 Col1 Col2 Col3 Col4 Col5 Col6 Col7
I have a table like col1 col2 col3 abc 123 A abc 345 B
I have a table that looks like this: Col1 Col2 Col3 Col4 a b
So I have this temp table that has structure like: col1 col2 col3 col3
I have a table that looks like this: id, col1, col2 col3 0 Goat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.