I have a basic SQL query, starting with:
SELECT top 20 application_id, [name], location_id FROM apps
Now, I would like to finish it so that it
You are asking different questions here. This is the answer to your original question (about the ternary operator, but as you can see, you don't need anything like a ternary operator for this):
SELECT top 20 application_id, [name], location_id
FROM apps
WHERE @lid = 0 OR location_id IN (@lid)
But that was before we knew that @lid was a varchar and could contain different comma separated values.
Well, this (about the csv) is another question which has been asked here before:
Passing an "in" list via stored procedure
T-SQL stored procedure that accepts multiple Id values