I'm using an sp_executesql so I can be flexible with what I choose to return. I'm encountering a problem when attempted to return data where there is none.
Say for instance I'm attempting to find all rows where there is no owner assigned. Currently, my query is written as follows.
if @owner <> ''
Begin
SELECT @sql = @sql + 'and owner LIKE ''%'+@owner+'%'''
END
This allows for me to not have to select an owner. If I do, it will of course be included in my query.
Since I'm now attempting to add a line that would basically allow me to just bring back unassigned owners:
if @owner = 'Unassigned'
BEGIN
SELECT @sql = @sql + 'and owner IS NULL'
END
However, when I'm doing this, it will bring back the entire list. Thoughts / suggestions?