看一下我的示例,是不是對你有幫助。
create table st_test ( id int ,name varchar(10),st varchar(100) )
insert st_test ( id,name )
select 1,"aa"
union select 1,"bb"
union select 1,"cc"
union select 2,"dd"
union select 3,"55"
union select 3,"777"
declare @c varchar(100)
declare @id int
declare cur_type cursor for
select distinct id from st_test
open cur_type
fetch cur_type into @id
while @@fetch_status = 0
begin
set @c = ""
select @c = @c + name from st_test f where f.id = @id
update st_test set st = @c
where id = @id
end
close cur_type
deallocate cur_type
看一下我的示例,是不是對你有幫助。
create table st_test ( id int ,name varchar(10),st varchar(100) )
insert st_test ( id,name )
select 1,"aa"
union select 1,"bb"
union select 1,"cc"
union select 2,"dd"
union select 3,"55"
union select 3,"777"
declare @c varchar(100)
declare @id int
declare cur_type cursor for
select distinct id from st_test
open cur_type
fetch cur_type into @id
while @@fetch_status = 0
begin
set @c = ""
select @c = @c + name from st_test f where f.id = @id
update st_test set st = @c
where id = @id
fetch cur_type into @id
end
close cur_type
deallocate cur_type