It works.
Yes, has nothing to do with OSQL, but nobody posted anything so I posted
this in place.
Ken Ambrose wrote:
>Hi,
> The below code may work, but it has nothing to do with using osql. Osql
>provides an api to run queries and output the results directly to files-
>no scripting or procedural code needed...
>
>Ken
>
>-----Original Message-----
>From: Aaron [mailto:[Email Address Removed]
>Sent: Wednesday, December 17, 2003 6:05 PM
>To: LazyDBA.com Discussion
>Subject: Re: saving to txt ?
>
>CREATE PROCEDURE sp_AppendToFile(@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
>
>
>
>Srikanth wrote:
>
>
>
>>How to do that?? Can anyone give me step by step procedure??
>>
>>Tq
>>Srikanth
>>----- Original Message -----
>>From: "Ken Ambrose" <[Email Address Removed] "LazyDBA.com Discussion" <[Email Address Removed] 17 December, 2003 12:23 AM
>>Subject: RE: saving to txt ?
>>
>>
>>Call osql from the sp. It will save to text for you.
>>
>>Ken
>>
>>-----Original Message-----
>>From: Usman Farhat [mailto:Usman.[Email Address Removed] Tuesday, December 16, 2003 2:05 AM
>>To: LazyDBA.com Discussion
>>Subject: saving to txt ?
>>
>>Hi Everyone,
>>
>>Is there exist any command in sql server that saves result of an query
>>to text file. Same function that we perform in query analyser - query
>>
>>
>->
>
>
>>result to file. Mine situation is to create a sp, that on call save
>>result set to an text file with name given.
>>
>>
>>Thanks,
>>Umsna
>>
>>--------------------------------------------------------------------
>>NOTA CONFIDENZIALE:
>>Questo messaggio ed i suoi allegati sono indirizzati esclusivamente
>>alle persone indicate in testa e possono contenere informazioni
>>confidenziali. Se avete ricevuto il messaggio per sbaglio, sappiate
>>che qualunque utilizzo improprio del contenuto è proibito, Vi
>>preghiamo quindi di inoltrarlo immediatamente al mittente e di
>>cancellare il messaggio. Per qualsiasi informazione vi inivitiamo a
>>contattarci scrivendo a [Email Address Removed] NOTICE:
>>This message and its attachments are addressed solely to the
>>persons
>>above and may contain confidential information. If you have
>>received
>>the message in error, be informed that any use of the content
>>hereof
>>is prohibited. Please return it immediately to the sender and
>>delete
>>the message. Should you have any questions, please contact us by
>>replying
>>to [Email Address Removed] you
>>--------------------------------------------------------------------
>>
>>---------------------------------------------------------------------
>>TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>>Get today's cartoon: http://www.LazyDBA.com
>>To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed] REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>>Get today's cartoon: http://www.LazyDBA.com
>>To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed] REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>>Get today's cartoon: http://www.LazyDBA.com
>>To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed]
>>
>>
>>
>
>
>---------------------------------------------------------------------
>TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>Get today's cartoon: http://www.LazyDBA.com
>To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed] REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY
>Get today's cartoon: http://www.LazyDBA.com
>To unsubscribe, e-mail: mssqldba-[Email Address Removed] additional commands, e-mail: mssqldba-[Email Address Removed]
>
MS Sql Server LazyDBA home page