string_split 值上的 SQL 连接 [英] SQL join on string_split values

查看:23
本文介绍了string_split 值上的 SQL 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个像这样的列值:

So, I have a column value something like this:

1,15,32,64

还有另一个表(称为 infoTable),其中标识符和文本位于单独的列中.将 infoTable 的数据从 mainTable 中获取到 select 的最佳方法是什么?

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 ?

我考虑过 string_split 但找不到任何关于我应该如何开始的信息.

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

我目前正在使用 MS SQL Server Manager Studio.

Im currently using MS SQL Server Manager Studio.

推荐答案

我认为您正在寻找 cross apply:

select t.*, i.text
from maintable t cross apply
     string_split(t.ids, ',') s join
     infotable i 
     on i.id = s.id;

这篇关于string_split 值上的 SQL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆