just a quick question here.
Lets say I have a stored procedure for seleting records from a table.
select * from tbl_table
where deleted = @deleted
So for this above, I must pass in a parameter being either TRUE or FALSE.
Is it possible to return results where deleted is equal to TRUE and FALSE but retaining the option to pass in a parameter. So I guess, if no parameter is passed in, there is no filter.
The other way I thought was to do this..
select * from tbl_table
where deleted = @deleted1
and deleted = @deleted2
So you have 2 parameters for the same filter. This way you can do true or false or set both filters the same – giving more leeway.
If anyone has any ideas or thoughts on this that would be great!
set your parameter as nullable (= NULL) and then
Then do not supply the parameter (or explicitly supply as NULL), when you do not want the filter by that parameter to be applied.
(But be aware this can sometimes have parameter sniffing consequences, especially with a large number of parameters)