为什么我的bcp查询出来在SQL Server中不起作用? [英] Why my bcp query out not work in sql server?
问题描述
我是 sql server
的新手,并且想要将选择查询保存到csv文件中,并为此目的使用bcp查询来编写此查询:
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.
推荐答案
在使用 queryout
时,您的来源必须是查询.
As you are using queryout
your source must be a query.
由于查询中有空格,因此必须将其引用:
As a query has got blanks, you have to quote it:
进一步,您的 @cmd nchar(50)
将会缩短,可能会截断您的命令.
Further more your @cmd nchar(50)
is to short and will probably truncate your command.
尝试一下:
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
通过 SELECT * FROM ...
查询,实际上更容易地使用由3部分组成的表名和 out
而不是SELECT ...
与 queryout
...
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
...
这篇关于为什么我的bcp查询出来在SQL Server中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!