开发者

bcp command not working

I'm using the following bcp command

BCP "select * from PACIFIC.dbo.CEOExtractCorpRulesView with(nolock) " 
   queryout "d:\temp\CEOExtractCorpRulesView.txt" 
   -S"tcp:BCBWEC-VIRTD2\SQL2005" -c -t"|!" -U"userid" -P"password" 

I get an error every time

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'queryout'.

Please let me know what the problem might be. This is not my script.

T开发者_如何学Chanks


I get the same error if I try and execute this script by pasting it into SSMS and clicking execute.

AFAIK you need to open a command window and run this.


If you have access to xp_cmdshell you can call bcp from that

exec xp_cmdshell 'BCP "select * from PACIFIC.dbo.CEOExtractCorpRulesView with(nolock) " 
   queryout "d:\temp\CEOExtractCorpRulesView.txt" 
   -S"tcp:BCBWEC-VIRTD2\SQL2005" -c -t"|!" -U"userid" -P"password" '

NOTE: I have not checked the above for proper character escaping... That's a pain.

Otherwise, you will have to run bcp from command line. It's a command-line tool. The T-SQL interpreter knows nothing of it.


Agreed with Martin. BCP is for the C prompt not for SQL Server Management Studio. To run it inside SSMS you need to use xp_cmdshell (and be logged as a user with rights to get to xp_cmdshell).


That looks like command line syntax to me. I don't think it works in SSMS.


Running BCP in command prompt with admin rights with unc path seem to work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜