You may not know this but you can have optional Parameters in SQL. It took me forever to figure it out.
In any case, you can implement an optional parameter by declaring a parameter in your stored procedure and giving it a default value of NULL, then in your WHERE clause, you just do a check to see if the parameter (with the NULL value) is NULL. An example follows:
CREATE PROCEDURE GetNameS@LastName VARCHAR(50) = NULL --Creating Optional ParameterASSELECT * FROM PersonalInfoWHERE (LastName = @LastName OR @LastName IS NULL)
In the above query I tested to see if the LastName field equals the supplied value or if the supplied value (the optional parameter) IS NULL.
?
?