表a的结构为
id point
1 (12),(34),(56)
2 (12)
3 (34),(5)
4 (8)
5 (9)
结果为
id point
1 (12)
1 (34)
1 (56)
2 (12)
3 (34)
3 (5)
4 (8)
5 (9)
谢谢大家了,在线等.....
---------------------------------------------------------------
--准备数据
declare @t table(id int,point varchar(100))
insert @t
select 1, '(12),(34),(56)' union all
select 2, '(12)' union all
select 3, '(34),(5)' union all
select 4, '(8)' union all
select 5, '(9)'
declare @ret table(id int,point varchar(100))--返回表
declare @id int,@point varchar(100)
declare c cursor for
select id,point from @t
open c
fetch next from c into @id,@point
while @@fetch_status = 0
begin
WHILE CHARINDEX(',',@point)>0
BEGIN
INSERT INTO @ret(id,point) VALUES(@id,LEFT(@point,CHARINDEX(',',@point)-1))
SET @point=RIGHT(@point,LEN(@point)-CHARINDEX(',',@point))
END
INSERT INTO @ret(id,point) VALUES(@id,@point)
fetch next from c into @id,@point
end
close c
deallocate c
select * from @ret