问题
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