Multiple questions here, but all relate to the same SQL Statement I'm working on...
I'm creating a stored procedure that needs to accept 5 separate parameters:
ID1, ID2 and ID3 are all integer record IDs
ID4 and ID5 need to contain multiple integer ID's.
So, I need to be able to do a query such as:
select * from X where a=@ID1 and b=@ID2 and c=@ID3
and d in (@ID4) and e in (@ID5)
Quest #1: @ID2 can be a valid ID (postive integer) or 0. If the value = 0, then I need all the records returned, with no filter applied. How can I put a conditional in the select to say "if @ID2=y then select all where b=y, else select b > 0"
Question #2: How would I pass ID4 and ID5 over? Is this possible?
Thanks!
I'm creating a stored procedure that needs to accept 5 separate parameters:
ID1, ID2 and ID3 are all integer record IDs
ID4 and ID5 need to contain multiple integer ID's.
So, I need to be able to do a query such as:
select * from X where a=@ID1 and b=@ID2 and c=@ID3
and d in (@ID4) and e in (@ID5)
Quest #1: @ID2 can be a valid ID (postive integer) or 0. If the value = 0, then I need all the records returned, with no filter applied. How can I put a conditional in the select to say "if @ID2=y then select all where b=y, else select b > 0"
Question #2: How would I pass ID4 and ID5 over? Is this possible?
Thanks!