| | |
Create stored procedure to make satic html content
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
hey,
first off I'd like to state that I am pretty new to ms sql and stored procedures tho I have worked with sql for quite some time.
My employer would like me to write a script which takes html content from a mssql db (originally delivered dynamically) and create static pages from them and also would like those tables locked until the script is run again. Now not sure if this will (should) fly because it may be limiting the admins to make changes to their content only during specific times.
But nonetheless, it has been requested. I just found out that ms sql can have access to the servers filesystem, which is cool because the web site and mssql are hosted on the same server.
Now I came a across a simple stored procedure that writes contents to a specified file:
What I would like is to have content from certain tables in their own folder and have an html file for each record in the tables. So for instance, say I have five tables, Article, Resource, Advice, Job, Company, then I would like to create folders (or goto predefined folders) for each table and have files for each record so that it's labled with it's primary key ID. So in the Articles folder I'd like to have article_1234.html, article_1235.html, article_1236.html ....
I'm sure you get the just of it. Is this possible with a stored procedure and if so, can anyone post some sample code I can use as a base?
first off I'd like to state that I am pretty new to ms sql and stored procedures tho I have worked with sql for quite some time.
My employer would like me to write a script which takes html content from a mssql db (originally delivered dynamically) and create static pages from them and also would like those tables locked until the script is run again. Now not sure if this will (should) fly because it may be limiting the admins to make changes to their content only during specific times.
But nonetheless, it has been requested. I just found out that ms sql can have access to the servers filesystem, which is cool because the web site and mssql are hosted on the same server.
Now I came a across a simple stored procedure that writes contents to a specified file:
sql Syntax (Toggle Plain Text)
CREATE PROCEDURE sp_OutputtoFile(@FileName VARCHAR(255), @Text1 VARCHAR(255)) AS DECLARE @FS INT, @OLEResult INT, @FileID INT EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject' --Open a file execute @OLEResult = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @FileName, 8, 1 IF @OLEResult <> 0 PRINT 'OpenTextFile' --Write Text1 execute @OLEResult = sp_OAMethod @FileID, 'WriteLine', NULL, @Text1 IF @OLEResult <> 0 PRINT 'WriteLine' EXECUTE @OLEResult = sp_OADestroy @FileID EXECUTE @OLEResult = sp_OADestroy @FS
What I would like is to have content from certain tables in their own folder and have an html file for each record in the tables. So for instance, say I have five tables, Article, Resource, Advice, Job, Company, then I would like to create folders (or goto predefined folders) for each table and have files for each record so that it's labled with it's primary key ID. So in the Articles folder I'd like to have article_1234.html, article_1235.html, article_1236.html ....
I'm sure you get the just of it. Is this possible with a stored procedure and if so, can anyone post some sample code I can use as a base?
This old function I made may help as it demonstrates the concepts of looping with SQL (without a yucky cursor!).
This may not be the most efficient way to iterate through the characters, but it gets the job done.
I would suggest setting up a table variable with the columns you want, along with an identity (1,1) or (0,1) column to iterate through it. For each pass through the loop, write to a file in a given directory. You can check which directory/file to write to on each iteration and while properly incrementing the LCV.
Hope this helps.
SQL Syntax (Toggle Plain Text)
CREATE function [dbo].[fn_Is_Uppercase] (@string VARCHAR(1000)) RETURNS BIT as BEGIN DECLARE @r BIT DECLARE @l INT DECLARE @i INT --trim it up SET @string = mrm.dbo.TRIM(@string) --need to check every character SET @l = len(@string) SET @i = 0 SET @r = 1 while @i <= @l + 1 AND @r = 1 BEGIN if ASCII(SUBSTRING(@string,@i - 1, 1)) <> ASCII(UPPER(SUBSTRING(@string,@i - 1, 1))) BEGIN SET @r = 0 END SET @i = @i + 1 END return @r END
This may not be the most efficient way to iterate through the characters, but it gets the job done.
I would suggest setting up a table variable with the columns you want, along with an identity (1,1) or (0,1) column to iterate through it. For each pass through the loop, write to a file in a given directory. You can check which directory/file to write to on each iteration and while properly incrementing the LCV.
Hope this helps.
Last edited by cutepinkbunnies; Jun 16th, 2009 at 7:59 pm.
![]() |
Similar Threads
- alter table stored procedure...???... (MS SQL)
- how to create-call stored procedure (PHP)
- exec command in stored procedure depends on condition (ASP.NET)
- Stored procedure in Oracle DB (ASP.NET)
- Need Stored Procedure "sp_ValidateUser" for Login Page (ASP.NET)
- Help with Stored Procedure (MS SQL)
- Stored procedure call with ADO (C)
Other Threads in the MS SQL Forum
- Previous Thread: Images, Audio and Video in MS-SQL Table
- Next Thread: How to handle high-volume inserts?
| Thread Tools | Search this Thread |





