使用存儲過程實現分頁打印。
這個存儲過程是一個小區寬帶用戶管理系統,項目里代碼的一部分。
功能是:
實現把表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) [email protected]
set @[email protected]@rowcount
if(@result>37)
begin
while(@result<74)
begin
insert into subip select
username='',catalyst_port='',home_address='',ip_address='',phone='',label='',account=''
set @[email protected]+1
end
end
else
begin
while (@result<37)
begin
insert into subip select
username='',catalyst_port='',home_address='',ip_address='',phone='',label='',account=''
set @[email protected]+1
end
end
--select @@rowcount
fetch next from cur_e into @subip
end
close cur_e
deallocate cur_e