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

来源:互联网 发布:linux system 头文件 编辑:程序博客网 时间:2024/06/05 11:25
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>


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

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

功能是:
实现把表userinfo里的用户资料按IP网段排序进行分页打印!!
比如172.20.128.XX的IP简称为128网段的用户,
172.20.119.XX的IP简称为119网段的用户,

每个网段的用户打印在一张A4纸上,
不足一张的按一张打印,其余的可空出。
大于一张小于两张的按二张打印,其余空出.
经过估算一页最多只能打印37行.
思路是:先把select出的按IP分组的用户信息和计算出的空格行insert进一个临时表中
然后多此临时表打印就行了。

 

--首先清空表
--truncatetablesubip

declare@resultint
declare@subipvarchar(20)
declarecur_escrollcursorfor
  selectsubstring(ip_address,8,3)fromuserinfogroupbysubstring(ip_address,8,3)

opencur_e--打开游标
--print'aaa'+convert(char(13),@@cursor_rows)
 fetchfirstfromcur_einto@subip

while(@@fetch_status=0)
 begin
 --insertintosubip(supip)values(@subip)
  insertintosubipselectuserinfo.username,userinfo.catalyst_port,userinfo.home_address,
userinfo.ip_address,userinfo.phone,catalyst.label,'fromuserinfo,
catalystwhereuserinfo.catalyst_id=catalyst.idandsubstring(userinfo.ip_address,8,3)=@subip
  set@result=@@rowcount
     if(@result>37)
       begin
         while(@result<74)
          begin
          insertintosubipselect

username=',catalyst_port=',home_address=',ip_address=',phone=',label=',account='
          set@result=@result+1
          end
       end
     else
       begin
         while(@result<37)
          begin
           insertintosubipselect

username=',catalyst_port=',home_address=',ip_address=',phone=',label=',account='
          set@result=@result+1
          end
        end
  --select@@rowcount
 fetchnextfromcur_einto@subip
 end
closecur_e
deallocatecur_e

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击