Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
exec master..xp_cmdshell 'BCP "select ''''empcode'''',''''fsname'''',''''ntype'''',''''desg'''',''''userid'''',''''dcr_count''''" queryout "d:\header.csv"  -c  -T -t'

when i execute the above query i would get error..i have mentioed below..please help me out..

SQLState = 37000, NativeError = 102
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near ''.
SQLState = 37000, NativeError = 8180
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement(s) could not be prepared.
NULL
Posted
Updated 26-Jun-15 0:09am
v2

1 solution

you can't use double quotes
use double single quotes instead. They should work fine:

SQL
exec master..xp_cmdshell 'BCP ''select ''''empcode'''',''''fsname'''',''''ntype'''',''''desg'''',''''userid'''',''''dcr_count'''''' queryout ''d:\header.csv''  -c  -T -t'
 
Share this answer
 
Comments
Member 11337367 26-Jun-15 6:16am    
Copy direction must be either 'in', 'out' or 'format'.
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]
[-d database name]
NULL

this error is showing
Andy Lanng 26-Jun-15 6:31am    
ok - that's good. It means that your syntax is now correct ^_^

This is, however, a different question. I have not used BCP before. I was able to help you with the question regarding syntax only :S

Please accept this solution and post a new question regarding the new error.

PS: I have done a quick search and it appears to be a well known confusion with BCP. I'm sure you'll get a good solution if you ask "Why do I get the error from BCP query 'Copy direction must be either 'in', 'out' or 'format'.'"

good luck ^_^
Member 11337367 26-Jun-15 7:33am    
i have posted new question but still not yet answered..pls help me out
Andy Lanng 26-Jun-15 7:36am    
have you searched google? There seem to be lots of people asking the same question.

Plus: it's Friday and this site is voluntary. It might just be bad timing :S

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900