Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » Rowset Functions RSS Feeds

OPENQUERY Function

Posted By: Sarita Patel     Category: SQL Server     Views: 7986

This article explains about OPENQUERY function in sql server with examples.

OPENQUERY function executes specified query on the given linked server, which is an OLE DB data source. The OPENQUERY function can be referenced in the FROM clause of a query. 

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.
  
Share: 

 
 

Didn't find what you were looking for? Find more on OPENQUERY Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of OPENQUERY Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!