Hi, given a simple stored procedure prototype as follows
How would I go about adding a select statement(s) for all possible combinations of input parameters?
i.e. I would like to do the following
Now this is just an example, including only two input fields, my real SP has several so there are hundreds of cobinations so the if else if style would be of no use.
Is there perhaps a way to build the query as a string or something (I'm a C++ programmer and don't write SP's that much so stating the obvious if fine )
Thanks,
Code:
CREATE PROCEDURE dbo.lookup
@first_name char (30),
@last_name char (30),
AS
/*work*/
GO
How would I go about adding a select statement(s) for all possible combinations of input parameters?
i.e. I would like to do the following
Code:
if @first_name not empty and last_name not empty then
SELECT * FROM names WHERE first = @first_name AND last = @last_name
elsif @first_name not empty
SELECT * FROM names WHERE first = @first_name
elsif @last_name not empty
SELECT * FROM names WHERE last = @last_name
end
Now this is just an example, including only two input fields, my real SP has several so there are hundreds of cobinations so the if else if style would be of no use.
Is there perhaps a way to build the query as a string or something (I'm a C++ programmer and don't write SP's that much so stating the obvious if fine )
Thanks,