Changing a SUM gab NULL auf Null zurück

Ich habe eine gespeicherte Prozedur wie folgt:

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 containts a generated list of total incidents by site/date (monthly)
'If a site doesnt have any incidents that month it wont be listed.

Das Problem, das ich habe, ist, dass eine Site in diesem Monat keine Vorfälle hat und als solches bekomme ich einen NULL-Wert für diese Site zurück, wenn ich diesen Sproc ausführe, aber ich muss eine Null / 0 zurückgeben, um innerhalb von a verwendet zu werden Diagramm in SSRS.

Ich habe versucht, die Verwendung von Coalesce und isnull ohne Erfolg.

    SELECT COALESCE(SUM(c.Logged,0))
    SELECT SUM(ISNULL(c.Logged,0))

Gibt es eine Möglichkeit, diese korrekt zu formatieren?

Prost

Le

Antworten auf die Frage(12)

Ihre Antwort auf die Frage