Running query against remote server

If you want to run a SQL Query against a remote server for example a different machine on the same network, you may want to use the flowing code. First link the server, then use OPENQUERY to run the query against the linked server. The two sql commands do not need to be executed in one batch. Example

Computer Name : MY-PC
Remote Server Name: SQLExpress1
Present Server Name: SQLExpress2

Example 2 – Remote Query

Do not forget single quotes around the query
Do not forget “Select * from” before OpenQuery statement.

2 Responses to Running query against remote server
  1. […] can try adding linked server from command line as […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*