declare @t table (aaa nvarchar(40) ,bbb nvarchar(30))
insert into @t select '13651343385,13651397907,13666360629','10001'
insert into @t select '13651343385,010-85860845,010-85860846','10002'
insert into @t select '010-85860847,010-85860848,010-85860849','10003'
insert into @t select '010-85860847,010-85860849,13666360629','10004'
insert into @t select '13651343385,010-85860850,010-85860851','10005'
insert into @t select '13651343385,13651397907,13666360629','10006'
insert into @t select '010-85861850,13651397907,010-85862850','10007'
select *
from @t
select CHARINDEX(',',aaa),len(aaa)
from @t
where bbb='10001'
--First step:在aaa每个记录最后面加逗号,目的是为了第二层循环的判断
update @t set aaa=aaa+','
--建立一张表用来存放循环结果,里面有两个字段
declare @i int
set @i=1
while @i<=(select count(aaa) from @t)
begin
--得到@t表中的每一条aaa的记录
declare @temp nvarchar(4000)
set @temp = select (select top 1 aaa from (select top @i aaa from @t order by bbb desc))
while charindex(',' @son_temp)=len(@temp)
begin
insert into (
sunbstring(charindex(',',(@temp ))