Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
yazasi
Starting Member
11 Posts |
Posted - 2010-08-06 : 18:18:15
|
Hi all,I do have a local table within SQL server from which I need to create a text file to my C:\ drive and name it EXAMPLE.TXTSelect *from TABLE(A)All returned records need to go to a text file that should be created within SQL commands.I don't want to use the right click then save result as .txt.Again this needs to be executed within a long script that should generate a final local table from which a text file should be created on my C:\ drive.Thank you for your help. |
|
KlausEngel
Yak Posting Veteran
85 Posts |
Posted - 2010-08-06 : 18:32:27
|
Try using the BCP command functionality. You may first have to enable the use of xp_cmdshell:EXEC master.dbo.sp_configure 'xp_cmdshell', 1RECONFIGURE Then use something like this.EXEC xp_cmdshell 'bcp "SELECT * FROM YourTable" queryout "C:\testfile.txt" -T -c -t,' this should work for the problem described. |
 |
|
yazasi
Starting Member
11 Posts |
Posted - 2010-08-09 : 13:39:44
|
Thanks it did work just fine. |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|