I have a Table Tab1
. I want to make a stored procedure, in which I will take up to 3 parameters from the user and select data from the table using the AND operator. Like:
Select * from Tab1
Where Para1=1 AND Para2=1 AND Para3=4
But I have a condition that the user can pass one, or two, or all three parameters. I want to write a single query such that if he passes all three parameters, then select data according these 3 parameters using the AND operator; if he passes any two parameters, select data according to those two parameters using the AND operator. Lastly, he may pass a single parameter, so then select data according this single parameter.
Is any way to write a single query for above requirement?