Luego de googlear un buen rato, encontré la solucion en simple-talk, sencilla, breve.
Pero no todo en la vida es tan simple… si vale la anécdota: el archivo generado era un html que funcionaba en Explorer pero no en Firefox? Cómo dijo? Sí. El html escrito a mano funcionaba en los dos… el html generado no. Diferencia? Genera texto Unicode.
Una hora más buscando la documentacion del método CreateTextFile/OpenTextFile de FileSystemObject, la encontré aquí. Basta con poner el parámetro format a False.
El código adaptado para que genere texto no Unicode es el siguiente:
CREATE PROCEDURE spWriteStringToFile -- Adaptado de http://www.simple-talk.com/code/WorkingWithFiles/spWriteStringTofile.txt -- por Juan Ayup 19/09/2007 ( @String Varchar(8000), --8000 in SQL Server 2000 @Path VARCHAR(255), @Filename VARCHAR(100) ) AS DECLARE @objFileSystem int ,@objTextStream int, @objErrorObject int, @strErrorMessage Varchar(1000), @Command varchar(1000), @hr int, @fileAndPath varchar(80) set nocount on select @strErrorMessage='opening the File System Object' EXECUTE @hr = sp_OACreate 'Scripting.FileSystemObject' , @objFileSystem OUT Select @FileAndPath=@path+'\'+@filename if @HR=0 Select @objErrorObject=@objFileSystem , @strErrorMessage='Creating file "'+@FileAndPath+'"' if @HR=0 execute @hr = sp_OAMethod @objFileSystem , 'CreateTextFile' , @objTextStream OUT, @FileAndPath,2,False if @HR=0 Select @objErrorObject=@objTextStream, @strErrorMessage='writing to the file "'+@FileAndPath+'"' if @HR=0 execute @hr = sp_OAMethod @objTextStream, 'Write', Null, @String if @HR=0 Select @objErrorObject=@objTextStream, @strErrorMessage='closing the file "'+@FileAndPath+'"' if @HR=0 execute @hr = sp_OAMethod @objTextStream, 'Close' if @hr<>0 begin Declare @Source varchar(255), @Description Varchar(255), @Helpfile Varchar(255), @HelpID int EXECUTE sp_OAGetErrorInfo @objErrorObject, @source output,@Description output,@Helpfile output,@HelpID output Select @strErrorMessage='Error whilst ' +coalesce(@strErrorMessage,'doing something') +', '+coalesce(@Description,'') raiserror (@strErrorMessage,16,1) end EXECUTE sp_OADestroy @objTextStream EXECUTE sp_OADestroy @objTextStream
Muy Buen Aporte.
Somos muchos los que estaremos pendientes de tus publicaciones.