If you want to filter out the rows where
Normal
and
Urgent
are both zero, then you can do that before you group them:
SELECT
a.Des as 'Alm',
SUM(CASE k.IdE WHEN 1 THEN 1 ELSE 0 END) As Normal,
SUM(CASE k.IdE WHEN 2 THEN 1 ELSE 0 END) As Urgent
FROM
TblKBA a
INNER JOIN TblKBK k
ON a.idA = k.IdAr
WHERE
k.IdE In (1, 2)
GROUP BY
a.Des
;
If you want to filter out rows where either
Normal
or
Urgent
is zero, then you can use the
HAVING
clause:
SELECT
a.Des as 'Alm',
SUM(CASE k.IdE WHEN 1 THEN 1 ELSE 0 END) As Normal,
SUM(CASE k.IdE WHEN 2 THEN 1 ELSE 0 END) As Urgent
FROM
TblKBA a
INNER JOIN TblKBK k
ON a.idA = k.IdAr
WHERE
k.IdE In (1, 2)
GROUP BY
a.Des
HAVING
SUM(CASE k.IdE WHEN 1 THEN 1 ELSE 0 END) != 0
And
SUM(CASE k.IdE WHEN 2 THEN 1 ELSE 0 END) != 0
;
HAVING (Transact-SQL) - SQL Server | Microsoft Docs[
^]