August 20, 2010 at 5:02 am
Dear forum members,
This is my script:
DECLARE @cmd VARCHAR(2048);
SET @cmd = 'bcp [Staedion Test].[dbo].[myTestNativeData] out "C:\myTestUniNativeData-N.csv" -N -T -t","';
EXEC master..xp_cmdshell @cmd
I get this error:
Copy direction must be either 'in', 'out' or 'format'.
Whats wrong, i gave the out option?
August 20, 2010 at 5:13 am
It looks like the space in the DB causes the problem, this works only now i have to play with the right user name:
DECLARE @cmd VARCHAR(2048);
SET @cmd = 'bcp [myTestNativeData] out "C:\myTestUniNativeData-N.csv" -N -T -t","';
EXEC master..xp_cmdshell @cmd
August 20, 2010 at 5:35 am
this is the result:
DECLARE @cmd VARCHAR(2048);
SET @cmd = 'bcp [myTestNativeData] out "C:\myTestUniNativeData-N.csv" -U<admabo> -N -T -t","';
EXEC xp_cmdshell @cmd
But now i get the following error:
The system cannot find the file specified.
I want the system to generate the file.
August 30, 2010 at 1:38 am
Solution found:
DECLARE @cmd VARCHAR(2048);
SET @cmd = --'bcp [myTestNativeData] out "/myTestUniNativeData-N.csv" -U<admabo> -N -T -t","';
'bcp "select * from [Staedion Test].[dbo].[Staedion$Werknemer Afdeling]" queryout C:\TEST.txt -S S-EMPACC -U admabo -N -T -t","';
EXEC xp_cmdshell @cmd
August 31, 2010 at 10:12 am
I would have thought that the following would work
DECLARE @cmd VARCHAR(2048);
SET @cmd = 'bcp "[Staedion Test].[dbo].[myTestNativeData]" out "C:\myTestUniNativeData-N.csv" -N -T -t","';
EXEC master..xp_cmdshell @cmd
In other words, since the dbtable parameter contains a space, you must enclose it in quotes.
This is a requirement of the standard Windows command processor which knows nothing about bcp or SQL naming conventions.
Martin
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply