I need the following query to return 0 if there is no match:
CREATE TABLE #Operations (
Discriminator varchar(40)
);
INSERT INTO #Operations
VALUES
('HistoricoCarga'),
('HistoricoDescarga')
;
SELECT
o.Discriminator,
CASE
WHEN COUNT(*) IS NULL THEN 0
ELSE COUNT(*)
END AS Total
FROM
HistoricosOperacion ho
RIGHT JOIN #Operations o
ON ho.Discriminator = o.Discriminator
WHERE
ho.FechaEnvioIntegracionUTC IS NULL
AND DATEDIFF(MINUTE, ho.FechaUTC, GETUTCDATE()) > 10
GROUP BY o.Discriminator;
I've tried changing the count(*) to count(ho.Discriminator) or changing the temp table to:
CREATE TABLE #Operations (
Discriminator varchar(40),
dummy int
);
INSERT INTO #Operations
VALUES
('HistoricoCarga', 0),
...
I need the output to be as follows:
HistoricoCarga 0
HistoricoDescarga 0