SQL Server static page export Technology 4

Source: Internet
Author: User
Tags copy datetime getdate variables variable web database
server| Static | Page This article extracts from the Railway publishing house new "use BackOffice to establish Intranet/extranet application" (now in Haidian Book city has been sold). This book details how to use the Microsoft BackOffice family of products to build intranet/extranet applications. With it you will master the installation and setup of NT, use IIS to set up a Web site, set up a network conferencing system through ILS, create an enterprise mail and collaboration system with Exchange, build Web database applications with SQL Server, and use proxy Server establishes secure connections to the Internet, creates network TV/radio stations with Media server, builds powerful chat rooms with Chart server, builds personalized mailing lists with Site server, and analyzes access to Web sites, Use Commerce Server to establish business-to-business or business-to-consumer e-commerce sites. In addition, the book also discusses the security of the network, which guides you through a more robust and secure network application. After reading this book, you will find that the implementation of the rich and colorful network applications is so simple ...
Absolutely original, welcome to reprint. But make sure you keep the above text.


Use test
Go
Declare
@riqi varchar (20),
@filepath varchar (255),
@listfile varchar (255),
@command varchar (255)
Set @riqi =left (CONVERT (varchar), GETDATE (), 20), 10)
Set @filepath = ' d:\webout\ ' + @riqi + ' \ '
Set @command = ' MD ' + @filepath
Execute Master.dbo.Xp_cmdshell @command
Set @command = ' MD ' + @filepath + ' images '
Execute Master.dbo.Xp_cmdshell @command
Set @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 @command
Set @listfile = @filepath + ' list.htm '
Execute sp_makewebtask
@outputfile = @listfile,
@query = ' SELECT DISTINCT Banmian
From Gaojian
Where kanwu= ' publishes ' and DATEPART (Yy,riqi) =datepart (Yy,getdate ()) and datepart (Dy,riqi) =datepart (Dy,getdate ()) ',
@templatefile = ' d:\test\list.tml ',
@codepage =936
In this code, some variables are defined to use when invoking the stored procedure. Where the @riqi variable is used to hold the date of the day (its format is YYY-MM-DD), @filepath variable is used to hold the path that generated the static page, @listfile variable is used to store the path and file name of the layout list paging file The @command variable is used to hold the system command to execute.
Then we assign the variables to each variable. and call the xp_cmdshell storage process to complete the establishment of the corresponding directory, copy files and so on. The xp_cmdshell storage process is an extended storage process used to perform an NT system command. Its grammatical structure is as follows:
xp_cmdshell {' command_string '} [, No_output]
Where the command_string parameter is the system command to execute. The option no_output is used to indicate that the execution results of the system commands are not output.
At the end of this code, the sp_makewebtask storage process without indicating the whentype parameter is executed, and the layout list paging file for the day is exported. The template file used is list.tml. The code for the list.tml file is as follows:
<body background= "Images/wb00703_.gif" >
<script>
var t=0;
</script>
<table border= "0" align= "CENTER" >
<%begindetail%>
<tr>
<td>
<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>As you can see, the template files used by the static page export are very similar to the HTX files used in the IDC technology. The <%begindetail%> and <%enddetail%> fields are also included. The difference is that the <% field name%> is not used in the template file to identify the field. Simply use <%insert_data_here%> to indicate where to insert the data in the result set. If the result set record contains more than one field,,<%insert_data_here%> inserts the data sequentially in the order in which it is in the record (that is, by the order of the fields in the SELECT statement). That is, each field in the result record can only be inserted once in the page. If you want to use a field more than once in a page, you can assign it to a variable first. You can then use this variable again and again.
There is a Java program in this template file that is used to generate hyperlinks for each layout in its order. Its links are the number of 1.htm~n.htm,n values for the day layout, respectively.
At this point we have successfully established a directory to store the paging file, completed the copy of the corresponding file, and exported the list file of the day layout. The article List page file is generated for each layout below.
Declare
@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= ' publications ' 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), @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= ' published ' 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
In this piece of code we use a cursor. The SQL statements we used before were used for collection operations. That is, statements are used only to produce a result collection, or to group the result collection. For each returned result record to be processed separately, the cursor is the only implementation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.