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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。