使用存储过程实现分页打印。
这个存储过程是一个小区宽带用户管理系统,项目里代码的一部分。
功能是:
实现把表userinfo里的用户资料按ip网段排序进行分页打印!!
比如172.20.128.xx的ip简称为128网段的用户,
172.20.119.xx的ip简称为119网段的用户,
每个网段的用户打印在一张a4纸上,
不足一张的按一张打印,其余的可空出。
大于一张小于两张的按二张打印,其余空出.
经过估算一页最多只能打印37行.
思路是:先把select出的按ip分组的用户信息和计算出的空格行insert进一个临时表中
然后多此临时表打印就行了。
--首先清空表
--truncate table subip
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)
open cur_e--打开游标
--print aaa+convert(char(13),@@cursor_rows)
fetch first from cur_e into @subip
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
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
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_e
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




