0

So, I have a column value something like this:

1,15,32,64

And another table (called infoTable) where the identifier and text is in seperate columns. What would be the best way to get the Data of the infoTable into an select from the mainTable ?

I've thought about string_split but cant find anything on how i should start with that.

Im currently using MS SQL Server Manager Studio.

Marcel H.
  • 111
  • 6

2 Answers2

2

I think you are looking for cross apply:

select t.*, i.text
from maintable t cross apply
     string_split(t.ids, ',') s join
     infotable i 
     on i.id = s.id;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

below is the join

select i.* FROM infoTable i
INNER JOIN string_split('1,15,32,64',',') sp
on i.columname=sp.value
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63