sqlsql-serversql-server-2008bcp

Can I specify an input sql file with bcp?


How can I specify an input sql file with a long query when using bcp? I tried using the -i option but it keeps complaining about a command-line error with no extra information. Is this possible?


Solution

  • As far as I'm concerned the BCP utility only supports Transact-SQL queries directly written to the command line. Ex:

    bcp "SELECT Name FROM AdventureWorks.Sales.Currency" queryout Currency.Name.dat -T -c

    According to its reference the "-i" option:

    Specifies the name of a response file, containing the responses to the command prompt questions for each data field when a bulk copy is being performed using interactive mode (-n, -c, -w, or -N not specified).

    Notice that it differs from the sqlcmd Utility "-i" option:

    Identifies the file that contains a batch of SQL statements or stored procedures. Multiple files may be specified that will be read and processed in order (...)