手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Mssql>列表

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

来源:互联网 作者:west263.com 时间:2008-04-02
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!


使用存储过程实现分页打印。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


文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!