I have, from what I can tell, a unique question. I would like to know if there's a way to construct a query in which the existence of the actual where clause itself is conditional.
I'm writing a stored procedure where I would like to pass in a filter (e.g.
Col1=1 or Col2=3) and my query looks something like the following:
set @filter = 'Col1=1 or Col2=3' --assume these variables have been declared already select * from @tbl where @filter --I need to use a table variable
Note: I tried using
sp_sqlexec but neither take a table variable. I would also like to avoid using an
if-else statement. Please do not suggest either of these as your answer. :)