create table tb(id int,mytype varchar(400))
insert into tb
select 1,'a,b,c,d' union all
select 2, 'c,f,a' union all
select 3, 'g'
go
declare @id int,@mytype varchar(10)
declare @tb table (id int,mytype varchar(10))
declare cur cursor for
select id,mytype from tb
open cur
fetch next from cur into @id,@mytype
while @@fetch_status=0
begin
set @mytype=@mytype+','
while charindex(',',@mytype)>0
begin
insert into @tb values(@id,left(@mytype,charindex(',',@mytype)-1) )
set @mytype=right(@mytype,len(@mytype)-charindex(',',@mytype))
end
fetch next from cur into @id,@mytype
end
close cur
deallocate cur
select * from @tb
drop table tb
go
insert into tb
select 1,'a,b,c,d' union all
select 2, 'c,f,a' union all
select 3, 'g'
go
declare @id int,@mytype varchar(10)
declare @tb table (id int,mytype varchar(10))
declare cur cursor for
select id,mytype from tb
open cur
fetch next from cur into @id,@mytype
while @@fetch_status=0
begin
set @mytype=@mytype+','
while charindex(',',@mytype)>0
begin
insert into @tb values(@id,left(@mytype,charindex(',',@mytype)-1) )
set @mytype=right(@mytype,len(@mytype)-charindex(',',@mytype))
end
fetch next from cur into @id,@mytype
end
close cur
deallocate cur
select * from @tb
drop table tb
go
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货