替换SQL Pivot中的空值 [英] replace null values in sql pivot
本文介绍了替换SQL Pivot中的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询:
SELECT *
FROM Table1
PIVOT
(
SUM(Value)
FOR [Period] IN ([06/1/2007],[07/1/2007])
)
AS p
返回的某些行为null,但我想将其替换为0.
Some of the rows returned are null but i want to replace them with 0.
我已经尝试过SUM(ISNULL(Value,0)) as Val
,但是它不起作用. (这是不正确的语法)
I've tried SUM(ISNULL(Value,0)) as Val
but it's not working. ( it's saying incorrect syntax)
推荐答案
哦,我在错误的地方使用了ISNULL
.
Ohh, I was using ISNULL
in the wrong place.
查询应如下所示:
SELECT ID,ISNULL([06/1/2007],0), ISNULL([07/1/2007],0)
FROM Table1
PIVOT
(
SUM(Value)
FOR [Period] IN ([06/1/2007],[07/1/2007])
)
AS p
这篇关于替换SQL Pivot中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文