Skip to content
Advertisement

Resolve split string in subquery

I have two tables in a Microsoft SQL Database, one contains 3 columns with separated values (by comma and/or slash, but both should be equally treated as a separator). Then I have another Table that contains an ID which is the same as each item in the split string from TABLE1. I want to resolve the items in TABLE 1 so the Text from the matching row in TABLE2 is displayed. Is there a way to achieve this?

TABLE1

TABLE2

Desired Result

I’m able to achieve this using C#, but i would very much prefer this to happen on the SQL side.

Advertisement

Answer

In the most recent version of SQL Server, you can do:

That said, fixing your data model should take precedence over trying to use it.

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