学习首页 百科 人生课堂 办公软件 英语学习 操作系统 故事会 编程资料 软件学习 设计
铭瑶网 >> 学习首页 >> 软件 >> SQL Server静态页面导出技术4
标题:SQL Server静态页面导出技术4

【字体: 】 时间:2008-4-11 来源:互联网 作者:study

SQL Server静态页面导出技术4

本段文章节选自铁道出版社新出的《用BackOffice建立Intranet/Extranet应用》一书(现已在海淀图书城有售)。本书详尽地讲述了如何使用微软BackOffice系列产品来组建Intranet/Extranet应用。通过它您将掌握NT的安装和设置、使用IIS建立Web站点、通过ILS建立网络会议系统、用Exchange建立企业的邮件和协作系统、用SQL Server建立Web数据库应用、用Proxy Server建立同Internet安全可靠的连接、用Media Server建立网络电视台/广播站、用Chart server建立功能强大的聊天室、用Site Server建立个性化的邮件列表和分析网站的访问情况、用Commerce Server建立B2B或B2C的电子商务网站。此外本书还对网络的安全性进行了讨论,从而指导您建立一个更为健壮和安全的网络应用。阅读本书之后,您将发现实现丰富多彩的网络应用原来这样简单……绝对原创,欢迎转载。但请务必保留以上文字。use testgodeclare     @riqi  varchar(20),    @filepath  varchar(255),    @listfile  varchar(255),    @command varchar(255)set @riqi=left(convert(varchar(40),getdate(),20),10) set @filepath=''d:\webout\''+@riqi+''\''set @command=''md ''+@filepathexecute master.dbo.Xp_cmdshell @command set @command=''md ''+@filepath+''images''execute master.dbo.Xp_cmdshell @commandset @command =''copy d:\test\files\*.* d:\webout\''+@riqi+''\''execute master.dbo.Xp_cmdshell @command set @command =''copy d:\test\files\images\*.* d:\webout\''+@riqi+''\images\''execute master.dbo.Xp_cmdshell @command set @command =''copy d:\test\''+@riqi+''\*.* d:\webout\''+@riqi+''\''execute master.dbo.Xp_cmdshell @commandset @listfile=@filepath+''list.htm''execute sp_makewebtask @outputfile=@listfile,@query=''select distinct banmianfrom gaojianwhere kanwu=''''出版报'''' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())'',@templatefile=''d:\test\list.tml'',@codepage=936    在此段代码中先定义了一些变量,用来调用存贮过程时使用。其中@riqi变量用于存放当日的日期(其格式为yyy-mm-dd);@filepath变量用于存放产生静态页面的路径;@listfile变量用于存放版面列表页面文件的路径和文件名;@command变量用于存放要执行的系统命令。    随后我们对各个变量进行赋值。并调用xp_cmdshell存贮过程来完成建立相应目录、拷贝文件等工作。xp_cmdshell存贮过程是一个用来执行NT系统命令的扩展存贮过程。其语法结构如下:    xp_cmdshell {''command_string''} [, no_output]    其中command_string参数为要执行的系统命令。而选项no_output则用来指明不输出系统命令的执行结果。    在此段代码的最后,执行未指明whentype参数的sp_makewebtask存贮过程,导出当日的版面列表页面文件。使用的模板文件为list.tml。list.tml文件的代码如下:<html><head><title>出版报</title></head><body BACKGROUND="images/WB00703_.gif"><script>var t=0;</script><table BORDER="0" ALIGN="CENTER"><%begindetail%><tr><td><img src="/Files/BeyondPic/jcwcj/2005-12/10/0512101120063651.gif"" WIDTH="14" HEIGHT="14"><script>var t=t+1;document.write(''<a HREF="'');document.write(t);document.write(''.htm" TARGET="show"><b><i><font SIZE="+1">'')</script><%insert_data_here%></font></i></b></a></td></tr><%enddetail%></table></body></html>    可以看到,静态页面导出使用的模板文件同IDC技术中使用的htx文件十分相似。其中也包含<%begindetail%>和<%enddetail%>字段。所不同的是,模板文件中不使用<%字段名%>来标识字段。只是简单的使用<%insert_data_here%>来指明在何处插入结果集中的数据。如果结果集记录中包含多个字段的话,<%insert_data_here%>将按照其在记录中的顺序(即按照SELECT语句中的字段顺序)来顺序地插入数据。也就是说,每个结果记录中的每个字段只能在页面中被插入一次。如果要想在页面中多次使用某个字段,可以先将它赋给一个变量。然后再反复地使用此变量即可。    在此模板文件中有一段Java程序,其用途是为每个版面按照其顺序产生超链接。其链接分别为1.htm~n.htm,n值为当日版面的数目。    至此我们已经成功地建立了存放页面文件的目录、完成了相应文件的拷贝工作、导出了当日版面的列表文件。下面将为每个版面来产生文章列表页面文件。declare @lists int,@banmian varchar(64),    @filename varchar(64),    @search varchar(2000)set @lists=0declare point cursor for select distinct banmianfrom gaojianwhere kanwu=''出版报'' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())for read onlyopen pointfetch point into   @banmianwhile (@@fetch_status=0)beginset @lists=@lists+1set @filename=@filepath+convert(varchar(64),@lists)+''.htm''set @search=''SELECT id,timu,laiyuan FROM gaojian WHERE datepart(yy,riqi)=datepart(yy,convert(datetime,''''''+@riqi+'''''')) and datepart(dy,riqi)=datepart(dy,convert(datetime,''''''+@riqi+''''''))''+''and banmian =''''''+@banmian+''''''and kanwu=''''出版报''''order by timu''execute sp_makewebtask @outputfile=@filename,@query=@search,@templatefile=''d:\test\list2.tml'',@codepage=936fetch point into @banmianendclose pointdeallocate point    在此段代码中我们使用了游标。在此之前我们所使用的SQL语句都是用于集合操作的。也就是说,语句只是用来产生结果集合,或对结果集合进行分组。而要想分别对每个返回的结果记录进行不同的处理,就只有通过游标来实现了。 

查看/参与:讨论/评论 相关文章:SQL