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

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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

这个存储过程是一个小区宽带用户管理系统,项目里代码的一部分。

功能是:

实现把表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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航