Skip to content
Advertisement

How to parse comma delimited list and join those values on another table and reconcatenate? [closed]

I’m looking for a way to parse a semicolon delimited list of values, join on another table using the values and return values from that other table and re-concatenate into a new field.

Here are the examples:

Table A:

Table A

Here is the table with the PFD values:

Table B:

Table B

Here is the results I’d like:

Table C:

Table C

Is this possible? Thank you!

Advertisement

Answer

Assuming you are using at least SQL Server 2016, you can use a combination of string_split and for xml path as follows:

Example DB<>Fiddle

If you happen to be using a version prior to 2016 you can use this alternative method that uses xml to split the value on ‘;’ instead of the string_split function:

Example DB<>Fiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement