It’s because a CASE WHEN
can only return 1 value.
And a STRING_SPLIT
returns a resultset.
I assume something like this is what you want.
SELECT *
FROM Facility f
WHERE (@Facility IS NULL OR f.facilityCode IN (SELECT value FROM string_split(@Facility,',')))
This will get all records if the variable is null.
2
solved Can I know the issue of this SQL query