BCP SQL 2014 Incorrect syntax near the keyword 'in'.

  • Hello,
    When I try to run below BCP command from SSMS SQL 2014 version or sqlcmd line
    bcp "[db_name].[dbo].[Table]" in "Q:\Table.txt" -c -T
    IT gives me this error,
    Msg 156, Level 15, State 1, Line 5
    Incorrect syntax near the keyword 'in'.

    When I just run this  bcp [db_name].[dbo].[Table] in "Q:\Table.txt" -c -T
    Then it gives this error,
    Msg 102, Level 15, State 1, Line 5
    Incorrect syntax near '.'.
    Please suggest

  • bcp is a command-line utility.  Run it from a Windows command prompt, not as a T-SQL query.

    John

  • Thanks John as I said I ran it from sqlcmd line tool.

  • You said you ran it in sqlcmd - that's effectively the same as running it in an SSMS query.  Run the cmd utility in Windows, and execute the command there.

    John

  • Thanks John. When I did it with cmd line, it was giving me very different error,
    I tried with -T integrated security. That account is sysadmin on sql.
    I also tried with  -U and  -P using sa account with sysadmin.
    Here it is,
    SQLState = 37000, NativeError = 4060Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot open database requested by the login. The login failed.

  • dallas13 - Friday, March 15, 2019 11:09 AM

    Thanks John. When I did it with cmd line, it was giving me very different error,
    I tried with -T integrated security. That account is sysadmin on sql.
    I also tried with  -U and  -P using sa account with sysadmin.
    Here it is,
    SQLState = 37000, NativeError = 4060Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot open database requested by the login. The login failed.

    The BCP command should work as listed in your example so the process in how you are doing this seems to be the issue.
    I tried different ways to make it fail from the command line or xp_cmdshell but didn't figure out what you are doing incorrectly. If you are still having issues, you probably need to post the details and all of the code you are using to do the bcp import. Maybe try explicitly specifying the server name. Use -S for the Servername\InstanceName

    Sue

  • Are you supplying a server name in your command line (-S)?  If not, it will likely look to the local machine, where you may have a SQL Express instance running.  What server is this supposed to go to?

  • Thanks a lot. I had a named instance so specifying a server name has resolved the issue for me. Thanks a lot.

Viewing 8 posts - 1 through 7 (of 7 total)

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