DECLARE rs CURSOR FOR SELECT scode FROM code_dhlb
open rs
--创建临时表
if OBJECT_ID('tempdb.dbo.#jyjfl') is not null --与sql 2000不同
drop table tempdb.dbo.#jyjfl
create table tempdb.dbo.#jyjfl (scode varchar(50),counts1 int,counts2 int)
--遍历
declare @scode int
fetch next from rs into @scode
while(@@fetch_status<>-1)
begin
print @scode
--1.
declare @counts1 int
select @counts1=count(*) from user_report_record where report_type=@scode
print '' + convert(varchar(20),@scode) + '=' + convert(varchar(20),@counts1)
--2.
declare @counts2 int
select @counts2=100
--
insert into tempdb.dbo.#jyjfl values (@scode,@counts1,@counts2)
--
fetch next from rs into @scode
end
--返回记录集
select * from tempdb.dbo.#jyjfl
close rs
deallocate rs
open rs
--创建临时表
if OBJECT_ID('tempdb.dbo.#jyjfl') is not null --与sql 2000不同
drop table tempdb.dbo.#jyjfl
create table tempdb.dbo.#jyjfl (scode varchar(50),counts1 int,counts2 int)
--遍历
declare @scode int
fetch next from rs into @scode
while(@@fetch_status<>-1)
begin
print @scode
--1.
declare @counts1 int
select @counts1=count(*) from user_report_record where report_type=@scode
print '' + convert(varchar(20),@scode) + '=' + convert(varchar(20),@counts1)
--2.
declare @counts2 int
select @counts2=100
--
insert into tempdb.dbo.#jyjfl values (@scode,@counts1,@counts2)
--
fetch next from rs into @scode
end
--返回记录集
select * from tempdb.dbo.#jyjfl
close rs
deallocate rs