The OPENQUERY function can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement, subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENQUERY returns only the first one.
OPENQUERY does not accept variables for its arguments.
Syntax of OPENQUERY Function :
OPENQUERY ( linked_server ,'query' )
linked_server is a linked server name.
query is a query string executed in the linked server.
Examples of OPENQUERY Function :
Example 1 : Use of OPENQUERY function in select clause
SELECT ContactName, CompanyName, ContactTitle
FROM OPENQUERY(ServerName, 'SELECT ContactName, ContactTitle FROM Customers')
Above example returns Customers contactname, companyname and contacttitle by creating linked server of specified server.