I'm trying to add count statements in SQL that have conditions, and I keep getting an error. Below is my code:
SELECT
(100.0*(COUNT(CASE [TYPE] WHEN 500 THEN 1 ELSE NULL END)) / (100*
(COUNT(CASE [TYPE] WHEN 400 THEN 1 ELSE NULL END + COUNT(CASE [TYPE] WHEN
300 THEN 1 ELSE NULL END))) AS Ratio
FROM historytable
Basically I'm trying to get the percentage of count of activity type 500 divided by count of activity type 400 and 300, and I keep getting an error.
NULLto0. That's probably your issue.