I need to create a stored procedure that can check for all records matching an indefinite number of values.
So for example take the following simple statement;
SELECT *
FROM some_table
WHERE ID = @param1
However, @param1
should be able to take a string of comma-delimited values and check against all of them eg:
@param1 = '1,2,45,16,476,324,'
I imagine this would need to take the values and then turn them into a temporary table, and then somehow create a sub query to check against all the values in the temporary table. However my T-SQL skills aren't quite up to tackling that on my own just yet.
How can I do this, or is there a better way to do it?
2条答案
按热度按时间xqk2d5yq1#
There are many split function version online, if you just google SQL Server Split function you will get 100s of results back.
A quick fix without a function would look something like......
Procedure
A proc would look something like...
cngwdvgl2#
What about this solution - using XML query. Table variable in procedure is created for test only.
How it works: