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
The following should do the trick for you.
DECLARE @lid SMALLINT
SET @lid = 0
SELECT top 20 application_id, [name], location_id
FROM apps
WHERE ((@lid > 0 AND location_id = @lid)
OR (@lid = 0 AND location_id > @lid))
If @lid = 0 then it will return ALL rows. IF @lid has a particular value, only the row for that @lid value is returned.