Displaying Values from a String as a List in SQL

Problem: You need to get values from a single field in a SQL table into a list that can be used in a sub-query or as a list of values in an SSRS report for example.


Example: I have a table called ValuesTable with a field called MyValues. I want to be able to parse out the values from MyValues and get them into a list that a can use as a parameter value in SSRS (just as one example)


Solution: The below code will convert the values to XML and then break them out into a usable list

You will get the following results:


Simply replace the field with your text field and the ';' with whatever your value delimiter is and you're ready to use your list in a variety of ways!