文章詳情頁
SQL Server靜態頁面導出技術4
瀏覽:105日期:2023-10-28 14:04:52
本段文章節選自鐵道出版社新出的《用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:testfiles*.* d:webout'+@riqi+''execute master.dbo.Xp_cmdshell @command set @command ='copy d:testfilesimages*.* 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:testlist.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="images/Yellowb2.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:testlist2.tml',@codepage=936fetch point into @banmianendclose pointdeallocate point;;;;在此段代碼中我們使用了游標。在此之前我們所使用的SQL語句都是用于集合操作的。也就是說,語句只是用來產生結果集合,或對結果集合進行分組。而要想分別對每個返回的結果記錄進行不同的處理,就只有通過游標來實現了。
標簽:
Sql Server
數據庫
排行榜
