SQL join on string_split values

眉间皱痕 提交于 2021-02-11 16:56:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!