[存储过程] 使用存储过程实现分页打印

发布时间:2010年01月27日      浏览次数:627 次
使用存储过程实现分页打印。www.c hinaitpower.comlhY4v8
这个存储过程是一个小区宽带用户管理系统,项目里代码的一部分。www.c hinaitpower.comlhY4v8
功能是:
实现把表userinfo里的用户资料按IP网段排序进行分页打印!!
比如172.20.128.XX的IP简称为128网段的用户,
172.20.119.XX的IP简称为119网段的用户,www.c hinaitpower.comlhY4v8
每个网段的用户打印在一张A4纸上,
不足一张的按一张打印,其余的可空出。
大于一张小于两张的按二张打印,其余空出.
经过估算一页最多只能打印37行.
思路是:先把select出的按IP分组的用户信息和计算出的空格行insert进一个临时表中
然后多此临时表打印就行了。www.c hinaitpower.comlhY4v8
www.c hinaitpower.comlhY4v8
--首先清空表
--truncate table subipwww.c hinaitpower.comlhY4v8
declare @result int
declare @subip varchar(20)
declare cur_e scroll cursor for
select substring(ip_address,8,3) from userinfo group by substring(ip_address,8,3)www.c hinaitpower.comlhY4v8
open cur_e--打开游标
--print 'aaa'+convert(char(13),@@cursor_rows)
fetch first from cur_e into @subipwww.c hinaitpower.comlhY4v8
while(@@fetch_status=0)
begin
--insert into subip (supip)values (@subip)
insert into subip select userinfo.username,userinfo.catalyst_port,userinfo.home_address,
userinfo.ip_address,userinfo.phone,catalyst.label,' from userinfo,
catalyst where userinfo.catalyst_id=catalyst.id and substring(userinfo.ip_address,8,3) =@subip
set @result=@@rowcount
if(@result>37)
begin
while(@result<74)
begin
insert into subip select www.c hinaitpower.comlhY4v8
username=',catalyst_port=',home_address=',ip_address=',phone=',label=',account='
set @result=@result+1
end
end
else
begin
while (@result<37)
begin
insert into subip select www.c hinaitpower.comlhY4v8
username=',catalyst_port=',home_address=',ip_address=',phone=',label=',account='
set @result=@result+1
end
end
--select @@rowcount
fetch next from cur_e into @subip
end
close cur_e
deallocate cur_ewww.c hinaitpower.comlhY4v8
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!