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 does it (written in pseudocode)
if @lid > 0 then WHERE location_id IN (@lid) else WHERE location_id is all values in location_id column
As requested, an example is provided.
application_id name location_id ---------------------------------------------------------- 1 Joe Blogs 33 2 Sam Smith 234 3 Jeremy Carr 33
@locid are user-defined results, e.g. '33, 234 '
If @lid is empty, I would like it to print all lines for location_id with name and application_id. Otherwise, I would like it to output all the lines with respect to the numbers provided in @lid (standing for location_id.
So if @lid is 0:
application_id name location_id ---------------------------------------------------------- 1 Joe Blogs 33 2 Sam Smith 234 3 Jeremy Carr 33
Otherwise, if @lid contains '33'
application_id name location_id ---------------------------------------------------------- 1 Joe Blogs 33 3 Jeremy Carr 33
sql sql-server tsql
Mike b
source share