• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

sqlserver 搞代码 7年前 (2018-06-16) 185次浏览 已收录 0个评论

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

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

http://www.gaodaima.com/35607.html使用存储过程实现分页打印_sqlserver

功能是:
实现把表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

欢迎大家阅读《使用存储过程实现分页打印_sqlserver,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:使用存储过程实现分页打印_sqlserver

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址