I’m working on a report in reporting services that has the user select a number of items from a multivalue list. The query for the report uses the resulting list in a simple
SELECT foo FROM bar WHERE foobar IN (@SelectedItemsFromMultiValueList)
I’m now altering the report and need to iterate over the items in @SelectedItemsFromMultiValueList using a cursor. I’ve looked around but can’t figure out how to do this – made even more difficult by the fact that I’m not sure what to call a list of values used in an IN or even declare one manually (eg. DECLARE @SelectedItemsFromMultiValueList ???)
Does anybody know how to cursor over a multivalue list parameter or how to call something like that in SQL so I can search more effectively for a solution?
Your multi-value list is going to come in to sql as a list of comma separated values (i.e. “31,26,17”)
To iterate through these values you need a way to split the values into a table. This is a function I have used, that I believe was originally coded by Jens Suessmeyer:
So you call this function, passing it @SelectedItemsFromMultiValueList and it will return to you a table of values that you can then do with what you want.
For example: