I have SP that selects data from a table with two columns like this
@param1 text,
@param2 text
Select * from tablle1 where field1 like @param1 and field2 like @param2
However , because sometimes Filed2 is null i had to do this , otherwise the query returned nothing
@param1 text,
@param2 text
Select * from tablle1 where field1 like @param1 and (field2 like @param2 OR field2 IS NULL)
My problem is that if I now try to run the SP with a value for @param2
and '%' for @param1
i get all the rows from the table
How can i make this in every situation ? I intend to use this SP in a search form on a asp.net site, and give the users the option to use '%' in searches.(eventually there would me more fields to search for and each one will have a textbox on the page that defaults to '%')