bcp usage syntax error

  • I am trying to run the following and I get the usage error. Please help.

    Declare @FileName varchar(50)

    DECLARE @BCPCommand varchar(7000)

    set @FileName = Replace('cds_returns'+convert(varchar(10),getdate(),101)+'.csv','/','')

    SET @BCPCommand = 'bcp "select receiver_name as Name

    ,BankAccountID as Account

    ,amount as Amount

    , tr as CheckingSavings

    , 063192874 as RT

    from postcard.dbo.ach_info" queryout "c:\test\' + @FileName + '" -c -T -S "POSTPRODDR.POSTCARD"'

    exec master.dbo.xp_cmdshell @BCPCommand

  • The output what I get is

    usage: bcp {dbtable | query} {in | out | queryout | format} datafile

    [-m maxerrors] [-f formatfile] [-e errfile]

    [-F firstrow] [-L lastrow] [-b batchsize]

    [-n native type] [-c character type] [-w wide character type]

    [-N keep non-text native] [-V file format version] [-q quoted identifier]

    [-C code page specifier] [-t field terminator] [-r row terminator]

    [-i inputfile] [-o outfile] [-a packetsize]

    [-S server name] [-U username] [-P password]

    [-T trusted connection] [-v version] [-R regional enable]

    [-k keep null values] [-E keep identity values]

    [-h "load hints"]

    NULL

  • First error I see is that you have the database name in the -S parameter. Remove the .POSTCARD and try again.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes, you are right. Database name does not need to be there. I added S option only when it was not working.

    The real reason for it not working was strange. Between RT and from there was no space but only new line so I did not notice that there is no space. When I was running just the query, it was running fine. But apparantly the space was needed when running the bcp command. As soon as I put space between RT and from, it worked. Thanks to all.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply