The solution I use alot ...
Put your list of numbers as a VARCHAR(MAX)
string with a comma, then use one of the many dbo.fn_split()
functions that people wrote on the line.
One of many online examples ... SQL-User-Defined-Function-to-Parse-a-Delimited-Str
These functions take a string as a parameter and return a table.
Then you can do things like ...
INSERT INTO @temp SELECT * FROM dbo.split(@myList) SELECT * FROM myTable INNER JOIN dbo.split(@myList) AS list ON list.id = myTable.id
An alternative is to view table values. They allow you to pass the entire table to the stored procedure as a parameter. How it depends on the structure used. You work in .NET, Java, Ruby, etc., and how do you communicate with the database?
As soon as we learn more detailed information about your application code, we can show you both the client code and the SQL stored procedure template for using table parameters.
source share