34,575
社区成员
SELECT T1.*,T2.* FROM [表1] as T1 LEFT JOIN [表2] as T2 ON T1.[编号数组] like '%'+T2.[编号]+'%'
可以关联,你要是不放心可以用concat('%',T2.[编号],'%')
但你的写法应该也是没问题的,至少我运行没有死循环,就是关联没有问题,个人认为死循环可能跟数据内容有关,你的编号数组与编号是否重复的有太多?
select t1.*,t2.* from (
SELECT 'a,1,2,3,a' as 编号数量, 't1' as 数组表数据
union all
SELECT 'a456a' as 编号数量, 't1' as 数组表数据
union all
SELECT 'a456a' as 编号数量, 't1' as 数组表数据
) t1 left join (
SELECT '1' as 编号, 't2' as 编号数据
union all
SELECT '2' as 编号, 't2' as 编号数据
union all
SELECT '3' as 编号, 't2' as 编号数据
union all
SELECT '4' as 编号, 't2' as 编号数据
union all
SELECT '5' as 编号, 't2' as 编号数据
union all
SELECT '6' as 编号, 't2' as 编号数据
union all
SELECT '1,2' as 编号, 't2' as 编号数据
union all
SELECT '45' as 编号, 't2' as 编号数据
) t2 on t1.编号数量 like '%'+t2.编号+'%'
你可以自己试一试,在sqlserver 2016 上是没有问题
第一个加号修改成and 第二个加号改成like,你这+号在条件后面不是拼接功能