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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Writing output to a txt file via bcp

Author  Topic 

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-09 : 15:25:20
I'm attempting to use the Bulk Copy Program to save query results to a file, and am not getting an error, however the file doesn't appear where I would expect it either:

EXEC master..xp_cmdshell 'bcp "SELECT TOP 10 * FROM AIP..AIP_FirstCallDetail_LatestA" QUERYOUT "C:\EXAMPLE01.TXT" -U "user" -P "password" -c'


I'm seeing this output from the query analyser:
NULL
Starting copy...
NULL
10 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 1 Average : (10000.00 rows per sec.)
NULL


It looks like it might be working, but I see no C:\EXAMPLE01.TXT file.

Any ideas?

X002548
Not Just a Number

15586 Posts

Posted - 2006-02-09 : 15:48:41
Let me guess....you're looking on your client.

The file is on the database server...

If you want to write it to your client, share a directory to public, and bcp it out to a unc name



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-10 : 10:31:56
Thanks Brett. Works like a charm.

Here's what I did:

EXEC master..xp_cmdshell
'bcp "SELECT TOP 10 * FROM DATABASE..TABLENAME" QUERYOUT "\\hostname\testing\EXAMPLE05.TXT" -Uusername -Ppassword -c -ec:\error.txt'


Note you can get your computer's hostname by typing hostname on the command line.

For those that don't know how to share a folder, you have to right click and select sharing. Be sure that you give write access.

The -ec paramater tells it to write errors out to a file.

Go to Top of Page
   

- Advertisement -