I have two columns Val1 and Val2 as int in SQL Server 2008. When I select Tot = Val1 + Val2 from the table, I get null as Tot
How to get the total number of selected two columns?
Thank you very much.
You probably have a null value in one of the columns. which will lead to a null result.
You can do the following if you want zero to represent 0.
SELECT Tot = ISNULL(Val1, 0) + ISNULL(Val2, 0) FROM Table
Use select Tot = isnull(Val1, 0) + isnull(Val2, 0) from Table
select Tot = isnull(Val1, 0) + isnull(Val2, 0) from Table