Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL select sum of Two integer column

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.

like image 455
user219628 Avatar asked Dec 22 '22 20:12

user219628


1 Answers

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
like image 105
bobs Avatar answered Jan 08 '23 04:01

bobs