It works ok for me on SQL2000 SP3, does the file exist ? Here's another version that will check if the file exists and create it if it doesn't, @append='Y' will append to an existing file CREATE PROCEDURE sp_writefile (@filename varchar(255),@msg varchar(255),@append char(1)='N')ASSET NOCOUNT ONDECLARE @hr intDECLARE @fso int DECLARE @file int DECLARE @exists varchar(5)DECLARE @ForAppending int ; SET @ForAppending = 8 /* Script Constant */EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso/* Check file exists */EXEC @hr=sp_OAMethod @fso, 'FileExists',@exists OUT, @filenameIF @hr <> 0 EXEC sp_OAGetErrorInfo @fsoIF @exists='True' /* File exists */BEGIN IF @append='Y' BEGIN EXEC @hr=sp_OAMethod @fso, 'OpenTextFile',@file OUT, @filename , @ForAppending IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso END ELSE BEGIN EXEC @hr=sp_OAMethod @fso, 'CreateTextFile',@file OUT, @filename , 'True' IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso ENDENDELSE BEGIN EXEC @hr=sp_OAMethod @fso, 'CreateTextFile',@file OUT, @filename IF @hr <> 0 EXEC sp_OAGetErrorInfo @fso ENDEXEC @hr=sp_OAMethod @file,'WriteLine',NULL,@msg IF @hr <> 0 EXEC sp_OAGetErrorInfo @fileEXEC @hr=sp_OADestroy @file IF @hr <> 0 EXEC sp_OAGetErrorInfo @fileEXEC @hr=sp_OADestroy @fso IF @hr <> 0 EXEC sp_OAGetErrorInfo @fsogo
HTHJasper Smith0x73656c6563742027546f6f206d7563682074696d65206f6e20796f75722068616e6473203f27