日期:2014-05-18 浏览次数:20598 次
--> 测试数据: @表A declare @表A table (ID int,Name varchar(1)) insert into @表A select 20,'a' union all select 120,'b' union all select 30,'c' union all select 41,'d' union all select 51,'e' --> 测试数据: @表B declare @表B table (Qu varchar(2),IDN varchar(10)) insert into @表B select 'la','41' union all select 'lb','30,20,120' select a.*,b.Qu from @表A a left join @表B b on charindex(','+ltrim(a.ID)+',',','+b.IDN+',')>0 /* ID Name Qu ----------- ---- ---- 20 a lb 120 b lb 30 c lb 41 d la 51 e NULL */