Problem Using BCP

I am trying to use BCP and failing at the first hurdle. I am running this on SQL Server 2008 SP2

Taking Nigel Rivett's most basic example from his simple talk article at http://www.simple-talk.com/sql/database-administration/creating-csv-files-using-bcp-and-stored-procedures/

BCP master..sysobjects out c:\sysobjects.txt -c -t, -T –S[ServerName]

(with [ServerName] replaced by the name of my server, double checked from the value of @@servername )

I just get:

    1> BCP master..sysobjects out c:\sysobjects.txt -c -t, -T -SJDUKDT001
    2> go
    Msg 102, Level 15, State 1, Server JDUKDT001, Line 1
    Incorrect syntax near '.'.

I get the same error in SSMS in SQL Cmd mode as well as using sqlcmd and it makes no difference if I enclose the table and output file in double quotes.

I have tried it with several other tables and options to no avail. For instance, if I use a query in quotes

Any ideas anyone?

Regards, Nigel Ainscoe

more ▼

asked Jan 07, 2010 at 07:10 PM in Default

avatar image

78 2 3 5

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

bcp is a command line tool. You should not execute it from inside sqlcmd or SSMS. If you have to, invoke a OS shell using xp_cmdshell.

more ▼

answered Jan 07, 2010 at 07:15 PM

avatar image

145 1 3 6

Thanks, that was the missing link. I'd got it into my head that it should/could be run from sqlcmd, and by implication in sqlcmd mode in SSMS

Jan 07, 2010 at 08:52 PM Nige
(comments are locked)
10|1200 characters needed characters left

BCP is not a SQL statement, it's a command line application. You can't run it directly in a SQL batch but you can shell out to it via xp_cmdshell. If you take a closer look at Nigel's article, he shows how to do this.

more ▼

answered Jan 07, 2010 at 07:26 PM

avatar image

David Wimbush
10.7k 31 34 44

Thanks for your reply. I had it running using xp_cmdshell, it was the sqlcmd bit that was confusing me.

Jan 07, 2010 at 08:53 PM Nige
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Jan 07, 2010 at 07:10 PM

Seen: 3660 times

Last Updated: Jan 07, 2010 at 07:10 PM

Copyright 2018 Redgate Software. Privacy Policy