sqlserver 2005存储过程与临时表
发布时间:2020-12-12 13:59:32 所属栏目:MsSql教程 来源:网络整理
导读: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
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |