TSQL execute sql statements across different instances

Answered TSQL execute sql statements across different instances

  • Friday, August 03, 2012 3:22 PM
     
     
    how can i  execute an SQL statement on a table in another instance? thanks!!

All Replies

  • Friday, August 03, 2012 3:24 PM
     
     Answered Has Code

    You can add the other instance as a Linked Server, then you can e.g. query it with such a statement using four-part-qualifier:

    SELECT *
    FROM [server].[database].[schema].[table]


    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich
    Blog Xing


  • Friday, August 03, 2012 3:24 PM
     
     

    Fully qualify the table name, provided you have a linked server established. 

    Something like: 

    SELECT Col1, Col2 FROM [linkedservername].[dbname].[schemaName].[TableName]


    Please mark as answer if this answers your question. Please mark as helpful if you found this post was helpful.

  • Friday, August 03, 2012 3:30 PM
     
     

    You can also use the openrowset t-sql command http://msdn.microsoft.com/en-us/library/ms190312.aspx

    Thanks,

    Luis