I am trying to choose between two select staments based on number of results. Each statement returns valid data when tested outside the following case statement.
SELECT CASE
WHEN Count(base.id) > 0 THEN base.id
ELSE (SELECT id
FROM tablea
WHERE pid = @val)
END
FROM (SELECT id
FROM tablea
WHERE id = @val) AS base
When base.Id >0 it retuns correct, otherwise Null when instead it should have 7 rows from my table