Link to home
Start Free TrialLog in
Avatar of mdward4
mdward4

asked on

bcp error usage: bcp {dbtable | query} {in | out | queryout | format} datafile

I am trying to write a procedure for Sql 2005 to export the results of a query to a flat file.  I keep receiving the error -

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]         [-x generate xml format file]

here is the code:  

declare @sql varchar(8000)

select @sql = 'bcp "select stockid from stock"
queryout c:\upload_pics\testshawn.txt  -T -S server\instance -U <user> -P <password> '

exec master..xp_cmdshell @sql

I can not seem to find what I am doing wrong.  
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

what version are you using?you might hit this issue: http://support.microsoft.com/kb/266224unless you simply remove the line feed:
declare @sql varchar(8000)

select @sql = 'bcp "select stockid from stock" queryout c:\upload_pics\testshawn.txt  -T -S server\instance -U <user> -P <password> '

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mdward4
mdward4

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mdward4
mdward4

ASKER

I got the procedure to work.