A fairly comprehensive query of the brain has turned up a thousand and one ways to pass variable length parameter lists that involve such methods as:
- CLR based methods for parsing strings to lists of integers
- Table valued functions that require the presence of a 'Numbers' table (wtf?)
- Passing the data as XML
Our requirements are to pass two variable length lists of integers (~max 20 ints) to a stored procedure. All methods outlined above seem to smell funny.
Is this just the way it has to be done, or is there a better way?
Edit: I've just found this, which may qualify this question as a dupe
Yes, I'd definitely look at Table Valued Parameters for this. As a side benefit, it may allow you to use a nice, clean set-based implementation for the innards of your procedure directly, without any data massaging required.
Here's another reference as well...
Here is a fairly fast method to split strings using only T-SQL and you input parameter is only a string. You need to have a table and a function (as described below) already set up to use this method.
create this table:
create this function to split the string array (I have other versions, where empty sections are eliminated and ones that do not return row numbers):
here is an example of how to split the parameter apart:
this is based on: http://www.sommarskog.se/arrays-in-sql.html