Why my bcp query out not work in sql server?

一笑奈何 提交于 2019-12-25 04:16:04

问题


I'm new in sql server and want to save select query into the csv file using with bcp query out for that purpose write this query:

declare @cmd as nchar(50)
SET @cmd = 'bcp  select *from [behzad].[dbo].[behzad] queryout "d:\spt_values.dat" -U behbeh -P beh1368421 ' 
EXEC master..XP_CMDSHELL @cmd  


but i get this output:

How can i solve this problem?thanks.


回答1:


As you are using queryout your source must be a query.

As a query has got blanks, you have to quote it:

Further more your @cmd nchar(50) is to short and will probably truncate your command.

Try this:

declare @cmd as nchar(500)
SET @cmd = 'bcp  "select * from [behzad].[dbo].[behzad]" queryout "d:\spt_values.dat" -U behbeh -P beh1368421 ' 
EXEC master..XP_CMDSHELL @cmd  

With a SELECT * FROM ... query it was easier actually, to use the 3-part-qualified table name together with out instead of a SELECT ... with queryout...



来源:https://stackoverflow.com/questions/39467075/why-my-bcp-query-out-not-work-in-sql-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!