Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 OLE sp_OAMethod @FileID, 'WriteLine',

Author  Topic 

Clages1
Yak Posting Veteran

69 Posts

Posted - 2013-04-29 : 19:09:20
Hi, its me again
I found this samples here,
but this sample APPEND the Text in the File
I would like to delete the file first..
in other words not to append.
i did not find the Option in "sp_OAMethod" .
something like sp_OAMethod @FS, 'DELETETextFile'

TKS
carlos lages
Dec






ALTER PROCEDURE [dbo].[sp_AppendToFile]
(@FileName varchar(255), @Text1 varchar(max))
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
   

- Advertisement -