已经全部通过验证:只要拷过去在sql2000上运行一下就行了
use test
go
create table test
(
[id] int not null primary key,
[no] char(4) not null ,
[name] varchar(10) not null,
Qty int not null
)
go
select * from dbo.test
go
insert into test values(1,'01','黄色',20)
insert into test values(2,'03','黑色',10)
insert into test values(3,'01','红色',60)
insert into test values(4,'04','红色',45)
insert into test values(5,'01','黑色',20)
go
select [name]+cast(Qty as varchar(5)) +'%' as test
from dbo.test
where [no]='01'
declare @test1 varchar(20),@test2 varchar(20)
declare cursor_name cursor
for
select [name]+convert(varchar(5),Qty)+'%' as char_id
from dbo.test
where [no]='01'
open cursor_name
fetch next from cursor_name into @test1
while @@FETCH_STATUS=0
begin
fetch next from cursor_name into @test2
select @test2=','+@test2
select @test1=@test1+@test2
end
print @test1
close cursor_name
deallocate cursor_name