SQL To create a text file

  • I'm able to run a SELECT statement and redirect the output to a file in the Query analyzer bt changin the out options - fine. Is there a way for to do the same thing only do it PURELY from SQL ??

    Like:

    Select Into File '\\MyFile.txt' * FROM MyTable

    ???

    Trying to avoid DTS and other wacky solutions. Just simple Transact-SQL please.

    Thanks in advance - B

  • The osql command prompt utility can output to a text file. You can execute from TSQL using the xp_cmdshell extended stored procedure.

    Regards,

    Andy Jones

    .

  • 1. Do not forget also about bcp utility.

    2. The other option is to use an ODBC driver for text files. This should allow you treat a text file as a table. I had never used the driver for text files but it should do the job.

  • I use BCP for it through an EXEC. Since Sql 2000, the stored proc for exec, as it allows return values.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply