OPENQUERY
Executes the specified pass-through query on the specified linked server.This server is an OLE DB data source. OPENQUERY can be referenced in the FROM clause of a query as if it were a table name. OPENQUERY can also be referenced as the target table of an INSERT, UPDATE, or DELETE statement. This is subject to the capabilities of the OLE DB provider. Although the query may return multiple result sets, OPENQUERY returns only the first one.
For Eg:
SELECT TOP 1* FROM OPENQUERY(TAW,'SELECT Column1,Column2
FROM DatabaseName.dbo.TableName')
Before running this query linked server has to becreated in the source server.Here 'TAW' is linkedserver name.
And most important thing is if we want to execute the stored procedure which is in other server we need to use OPENQUERY compulsorily.
For Eg:
SELECT TOP 1* FROM OPENQUERY(TAW,'SELECT Column1,Column2
FROM DatabaseName.dbo.TableName')
Before running this query linked server has to becreated in the source server.Here 'TAW' is linkedserver name.
And most important thing is if we want to execute the stored procedure which is in other server we need to use OPENQUERY compulsorily.
Comments