Often, we need to create a flexible stored procedure that returns data that is optionally filtered by some parameters. If you wish to apply a filter, you set the parameter to the necessary value, if not, you leave it null. This is pretty standard stuff, of course, that we can write fairly easily, without the need for dynamic SQL, like this: create procedure GetData @MinDate int = null, @MaxDate int = null, @MinAmount money = null, @MaxAmount money = null, @ProductCode varchar(200) = null, @CompanyID int as select * from Data where (@MinDate is null OR @MinDate (@MaxDate is null OR @MaxDate >= Date) and (@MinAmount is null OR @MinAmount >= Amount) and (@MaxAmount is null OR @MaxAmount (@ProductCode is null OR ProductCode = @ProductCode) and (@CompanyID is null OR CompanyID = @CompanyID) Note that we are using good boolean algebra as discussed here, and not using inefficient CASE or COALESCE() exp...