Click to See Complete Forum and Search --> : Stored procedures wild card?


loiter
March 19th, 2003, 03:34 PM
Hello,

I have a parameter I am sending to a SP, if the parameter is null, I want the SP to return all rows possible (like a wildcard).

I just need to know what the code is in the SP to return all rows if the parameter has no value.

Thanks,
J

antares686
March 21st, 2003, 06:11 AM
This is the way I handle hanving an unsubmitted parameter.


CREATE PROCEDURE ip_MyProc
@param1 varchar(50) = NULL /* Use defaults for parameters so you do not have to pass. */
AS

SET NOCOUNT ON

if @param1 IS NULL
--do thing without param1 input
ELSE
-- do thing with param1 input


There are further things you can do to maximize the SPs performance but using defaults make submitting much easier and conditional checking allows optional coding.