我有一个存储过程如下:
CREATE PROC [dbo].[Incidents]
(@SiteName varchar(200))
AS
SELECT
(
SELECT SUM(i.Logged)
FROM tbl_Sites s
INNER JOIN tbl_Incidents i
ON s.Location = i.Location
WHERE s.Sites = @SiteName AND i.[month] = DATEADD(mm, DATEDIFF(mm, 0, GetDate()) -1,0)
GROUP BY s.Sites
) AS LoggedIncidents
'tbl_Sites contains a list of reported on sites.
'tbl_Incidents contains a generated list of total incidents by site/date (monthly)
'If a site doesn't have any incidents that month it wont be listed.
我遇到的问题是该站点本月没有任何事件,因此当我运行此 proc 时,我为该站点返回了一个 NULL 值,但我需要返回一个零/0 才能在其中使用SSRS 中的图表。
我试过使用 coalesce 和 isnull 无济于事。
SELECT COALESCE(SUM(c.Logged,0))
SELECT SUM(ISNULL(c.Logged,0))
有没有办法让这个格式正确?
干杯,
李