I have a large number of stored procedures that basically do the same thing: get a list of values as parameters, then go to some table and SELECT all the rows WHERE these values match.
I would like to be able to have a single stored procedure that would be able to handle all these cases.
How would you tackle this?
You can try to use XML based approach for your problem. Send an XML as an input parameter. Convert the xml into a table. From the table form dynamic query and execute it in order to achieve your desired functionality. See the below example. In this example Departments is a table which contains 3 columns pkDepartmentId (int), DepartmentName (varchar) and BuildingNumber (int). Using this approach you can send n Number of parameters and their values as input parameters.
pkDepartmentId DepartmentName BuildingNumber
1 Electronics and Communication 1
2 Computer Science 2
3 Instrumentation and Technology 4
On executing this proc following result is obtained
pkDepartmentId DepartmentName BuildingNumber
1 Electronics and Communication 1