如何处理NULL以在T-SQL查询中显示0

时间:2017-06-23 12:53:08

标签: sql sql-server tsql

当Null为结果时,如何将下面的SQL语句更改为显示0而不是Null?

SELECT cast (sum([ColumnA]) as DECIMAL(18,0)) AS [Weight] 
FROM [DB1].[dbo].[Tabel1]

1 个答案:

答案 0 :(得分:0)

这应该有效:

SELECT cast(COALESCE(sum([ColumnA]), 0) as DECIMAL(18,0)) AS [Weight] 
FROM [DB1].[dbo].[Tabel1]