T-SQL select sum of Two integer column

11,422

Solution 1

It's likely that you have a null value in one of the columns. that will produce a null-valued result.

You can do the following, if you want null to represent 0.

SELECT Tot = ISNULL(Val1, 0) + ISNULL(Val2, 0)
FROM Table

Solution 2

Use select Tot = isnull(Val1, 0) + isnull(Val2, 0) from Table

Share:
11,422
user219628
Author by

user219628

Updated on June 05, 2022

Comments

  • user219628
    user219628 about 2 years

    I have two columns Val1 and Val2 as int in SQL Server 2008 When I select Tot = Val1+Val2 from Table, I get null as Tot

    How do I get total of two int columns selected?

    Many thanks.