问题
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.
回答1:
below is the join
select i.* FROM infoTable i
INNER JOIN string_split('1,15,32,64',',') sp
on i.columname=sp.value
回答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;
来源:https://stackoverflow.com/questions/65788096/sql-join-on-string-split-values