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
返回的某些行是空的,但我想用 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 中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!