Saving data to a Text File | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Saving data to a Text File

I want to save data from a SELECT statement to a text file.What is the code for doing this?
Read about bcp in sql server help file Madhivanan Failing to plan is Planning to fail
Check this topic:
You can also use the following commands to write to a file if you wanted to do it in a sp or something else. Once you open the file, you can write to it as many times as you want before you close it. If the file does not exist, it will create it. If the file does exist, it will append to it. *************************************************************************************
OK well I can’t seem to post the part declaring a Scripting.FileSystemObject so the code is at the address shown below. Sorry I just get an error each time.
************************************************************************************* I believe I got this script at the following address. The person has this in a stored procedure for file output. John
If its a one-off then from Query analyzer you can save the results to a text file [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />].<br /><br /><hr noshade size="1"><b>Satya SKJ</b><br />Microsoft SQL Server MVP<br />Contributing Editor & Forums Moderator<br /<a target="_blank" href=http://www.SQL-Server-Performance.Com>http://www.SQL-Server-Performance.Com</a><br /><center><font color="teal"><font size="1">This posting is provided “AS IS” with no rights for the sake of <i>knowledge sharing.</i></font id="size1"></font id="teal"></center>