萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> sql server教程 >> 使用存儲過程實現分頁打印

使用存儲過程實現分頁打印


使用存儲過程實現分頁打印。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


關鍵詞:打印 

copyright © 萬盛學電腦網 all rights reserved