I have a stored procedure that needs to filter by a list of ids that are passed as a comma-delimited list (ie '1,2,3'
).
I want to apply a WHERE IN
clause that will match those ids but ONLY if the variable contains anything (IS NOT NULL AND <> ''
).
Here's a simplified fiddle of the problem: http://sqlfiddle.com/#!18/5f6be/1
It's currently working for single and multiple ids. But when passing ''
or NULL
it should return everything but it's not returning anything.
The CTEs and pagination stuff is there for a reason, please provide a solution that doesn't change that.