SQL Server静态页面导出技术4

80酷酷网    80kuku.com

  server|静态|页面本段文章节选自铁道出版社新出的《用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 test
go
declare
    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 '+filepath
execute master.dbo. command
set command='md '+filepath+'images'
execute master.dbo. command
set command ='copy d:\test\files\*.* d:\webout\'+riqi+'\'
execute master.dbo. command
set command ='copy d:\test\files\images\*.* d:\webout\'+riqi+'\images\'
execute master.dbo. command
set command ='copy d:\test\'+riqi+'\*.* d:\webout\'+riqi+'\'
execute master.dbo. command
set listfile=filepath+'list.htm'
execute sp_makewebtask
outputfile=listfile,
query='select distinct banmian
from gaojian
where 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变量用于存放要执行的系统命令。
    随后我们对各个变量进行赋值。并调用存贮过程来完成建立相应目录、拷贝文件等工作。存贮过程是一个用来执行NT系统命令的扩展存贮过程。其语法结构如下:
     {'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="http://edu.cnzz.cn/NewsInfo/images/Yellowb2.gif" WIDTH="14" HEIGHT="14">
<script>
var t=t+1;
document.write('<a
lists int,
banmian varchar(64),
    filename varchar(64),
    search varchar(2000)
set lists=0
declare point cursor for
select distinct banmian
from gaojian
where kanwu='出版报' and datepart(yy,riqi)=datepart(yy,getdate()) and datepart(dy,riqi)=datepart(dy,getdate())
for read only

open point
fetch point into
  banmian
while (fetch_status=0)
begin
set lists=lists+1
set 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=936
fetch point into
banmian
end
close point
deallocate point
    在此段代码中我们使用了游标。在此之前我们所使用的SQL语句都是用于集合操作的。也就是说,语句只是用来产生结果集合,或对结果集合进行分组。而要想分别对每个返回的结果记录进行不同的处理,就只有通过游标来实现了。


分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: