How to find sum of multiple columns in a table in SQL Server 2005?

后端 未结 8 1992
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 17:13

I have a table Emp which has these rows:

Emp_cd | Val1  | Val2  | Val3  | Total
-------+-------+-------+-------+-------
 1     | 1.23  | 2.23  |         


        
8条回答
  •  误落风尘
    2020-12-04 17:52

    You must also be aware of null records:

    SELECT  (ISNULL(Val1,0) + ISNULL(Val2,0) + ISNULL(Val3,0)) as 'Total'
    FROM Emp
    

    Usage of ISNULL:

    ISNULL(col_Name, replace value)
    

提交回复
热议问题