locked
BCP command RRS feed

  • Question

  • I am using below command in BCP but it's not working. because EMP table is different server and config is in different server.

    EMP table is in  server1

    config table is in server2

    Running the BCP command from config table server but it's showing invalid config table. I think it's looking config table in EMP server. is there a way to fix this issue.

    Select * from %database%.dbo.EMP (NOLOCK) where EMPID > (Select EMPID from %config_database%.dbo.Config ) and EMPIDID <= 10" queryout %folderpath%EMP.txt -c -T -S %servername%


    srinivas



    Friday, January 3, 2014 8:20 PM

Answers

  • Since the query is executed on the server where the EMP table is located, %config_database% needs to be on the form server.database. And obviously a linked server has to exist on the source server.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    • Proposed as answer by Kalman Toth Saturday, January 4, 2014 10:04 PM
    • Marked as answer by Kalman Toth Monday, January 13, 2014 12:35 AM
    Friday, January 3, 2014 11:28 PM

All replies

  • Because you are specifying servername, BCP will look for the databases in the server specified. From where are you calling this BCP?
    Friday, January 3, 2014 9:12 PM
  • Since the query is executed on the server where the EMP table is located, %config_database% needs to be on the form server.database. And obviously a linked server has to exist on the source server.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    • Proposed as answer by Kalman Toth Saturday, January 4, 2014 10:04 PM
    • Marked as answer by Kalman Toth Monday, January 13, 2014 12:35 AM
    Friday, January 3, 2014 11:28 PM