Hi, I'd like to make a stored procedure that checks the list of parameters and only compares the ones that are not null. I assume that means that I set the default parameters to NULL, or that when I call the stored procedure I pass in null values. How do I set the select statement then? I have something like this:
but you can see, it doesn't compare for the idea that if it is null, ignore that parameter and select them all.
Any ideas?
Thanks,
James
Code:
CREATE PROCEDURE SELECT_PROJECTS
-- Add the parameters for the stored procedure here
@p1 int = null,
@p2 int = null
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from tblProject where int_fk_PortfolioID = @p1
END
but you can see, it doesn't compare for the idea that if it is null, ignore that parameter and select them all.
Any ideas?
Thanks,
James