TSQL execute sql statements across different instances
-
Friday, August 03, 2012 3:22 PMhow can i execute an SQL statement on a table in another instance? thanks!!
All Replies
-
Friday, August 03, 2012 3:24 PM
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- Edited by Olaf HelperMicrosoft Community Contributor Friday, August 03, 2012 3:24 PM Link
- Proposed As Answer by Hasham NiazEditor Friday, August 03, 2012 4:13 PM
- Marked As Answer by lochnesse Friday, August 03, 2012 5:07 PM
-
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

