BCP utility in procedure gives strange erros

  • 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?

  • 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

  • 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.

  • 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

  • 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