What is a good way to handle dynamic sql parameters?
I have a search form that takes in a whole bunch of different search parameters. If the parameters are empty an
One of the things that can be done is check whether the parameter was passed to your stored procedure. You can do it like this:
create procedure my_procedure (
@param1 as int = null
@param2 as int = null
) as
begin
select field1, field2, fieldn
from table
where ((@param1 is null) or (field2 = @param1))
and ((@param2 is null) or (field2 = @param2))
end
I'd rather do this on sql procedure than in the application tho