我正在运行此更新查询,我希望它会更新表以保持值为0而不是在计数为0时显示NULL。如何更新以强制表,因此在显示时显示0返回的计数是0?
set @sql =
'UPDATE cra
SET mastercounts = te.LC
FROM #tbl_test As cra
JOIN (
select
,COUNT(CASE WHEN recordID < 1 THEN 0 ELSE recordID end) As LC
,employeename
from productioninformaiton
where salestatus = (''Approved'', ''Shipped'')
Group By employeename
) As te
ON cra.[StoreName] = te.[StoreName]
AND cra.[employeename] = te.[employeename]'
Exec (@sql)
答案 0 :(得分:1)
也许是字段&#34; recordID&#34;在某些情况下返回NULL,这使得COUNT(NULL)也返回NULL。尝试替换
COUNT(CASE WHEN recordID < 1 THEN 0 ELSE recordID end) As LC
带
COUNT(CASE WHEN ISNULL(recordID, 0) < 1 THEN 0 ELSE ISNULL(recordID, 0) end) As LC