OPENQUERY is a T-SQL function that allows for executing a pass-through query on a linked server. The linked server should be an OLE DB data source. OPENQUERY is used in SELECT, INSERT, DELETE and UPDATE statements as if it were a table name.
Questions tagged [openquery]
421 questions
3
votes
1 answer
Extremely slow insert OpenQuery performance on SQL Server to MySQL linked server
Using SQL Server Management Studio to copy the entire contents of a table from SQL Server to an identical table on a MySQL machine. The MySQL db is connected to Management Studio as a linked server using MySQL ODBC 5.1 driver. Using a simple…

justaguy
- 31
- 1
- 2
3
votes
0 answers
Open Query SQL Server 2016 Update clause
I have 2 tables. Table 1: Source that is in Oracle cloud and Table 2: in sql server 2016 on prem server. We have a request to update the on-prem data with cloud data based on some joining column(s).
Question is how do i update via open query on prem…

junketsu
- 533
- 5
- 17
3
votes
0 answers
SQL / ADSI query with Thumbnail Limit of 4000 characters
I'm querying AD to pull user details incl. thumbnail into an SQL service using an OPENQUERY call (see below):
CREATE TABLE #ADContacts(Name VARCHAR(100), Company VARCHAR(100), Title VARCHAR(100),
Landline VARCHAR(100), Mobile…

Steve Buchanan
- 31
- 2
3
votes
1 answer
How to incorporate OpenQuery into an SSDT project (without SQL71501/'unresolved reference to object' errors)
I have a Visual Studio SSDT project where one view references a linked server via 4 part naming. I have set up a project for the database on the linked server and created a reference from the main project to the "linked server" project, and all…

ubienewbie
- 1,771
- 17
- 31
3
votes
1 answer
Update a table on a Linked Server using OPENQUERY
I have two servers: SQLSERVER01 and SQLSERVER02 and I am trying to updated data on SERVER01 from SERVER02 (SERVER01 is a linked server).
My update query is currently dynamic which looks something like this
DECLARE @SQL NVARCHAR(MAX)
DECLARE @ID…

Palps
- 568
- 9
- 20
3
votes
2 answers
How to handle an empty result set from an OpenQuery call to linked analysis server in dynamic SQL?
I have a number of stored procedures structured similarly to this:
DECLARE @sql NVARCHAR(MAX)
DECLARE @mdx NVARCHAR(MAX)
CREATE table #result
(
[col1] NVARCHAR(50),
[col2] INT,
[col3] INT
)
SET @mdx = '{some dynamic MDX}'
SET @sql = 'SELECT…

Cendenta
- 170
- 2
- 10
3
votes
0 answers
Can "INSERT INTO OPENQUERY" be used inside a transaction?
I am trying to run transaction in SQL Server, where my code will insert data into MySQL server.
I begin a transaction inside a try catch block and from there I commit/rollback.
The problem is that I keep getting this error
(1 row(s) affected)
OLE DB…

Jaylen
- 39,043
- 40
- 128
- 221
3
votes
2 answers
Lotus Domino NotesSQL ODBC & SQL 2008 query
I'm trying to work at getting the same information from a couple different sources but have hit a wall in trying to use NotesSQL and SQL 2008. What I am trying to do is to retrieve info from a couple different views on Domino servers. One view is…

steve_o
- 1,243
- 6
- 34
- 60
3
votes
2 answers
Wide varchar field causes "Requested conversion is not supported" error using openquery with MySQL linked server
I'm trying to migrate a table from MySql to MSSQL using openquery but I keep getting the following error message:
OLE DB provider "MSDASQL" for linked server "MYSQL" returned message "Requested conversion is not supported.".
Msg 7341, Level 16,…

papaiatis
- 4,231
- 4
- 26
- 38
2
votes
2 answers
Linked Server - LDAP - Msg 7321
Below is an abbreviated query I am trying to execute against LDAP using a linked server:
select * from openquery(ADSI,'')
The query runs fine, except when I change the "Domain controller: LDAP server signing requirements" security setting to…

Kevin Barker
- 63
- 6
2
votes
0 answers
Openquery Data Type Conversion
I have created a linked server to query some CSV files. The query below works with no errors:
SELECT * FROM OPENQUERY(LINKEDSERVER, 'Select * FROM [import.csv]')
There is a field that could contain either an number or text and the query seems to…

Ron
- 61
- 3
2
votes
0 answers
Move Image column from OracleDB top SQL Server
I have access to an Oracle database and I need to bring its data into SQL Server. The table has a simple structure and I can't change anything on the Oracle side.
I created a linked server inside SQL Server but I can't select the table because of…

Pouya Kamyar
- 133
- 1
- 9
2
votes
1 answer
order hint for openquery?
I need to execute the following SQL (SQL Server 2008) in a scheduled job periodically. The Query plan shows 53% cost is sort after the data is pulled from the oracle server. However, I've ordered the data in the openquery. How to force the query not…

ca9163d9
- 27,283
- 64
- 210
- 413
2
votes
0 answers
SQL Server linked-server supplied inconsistent metadata for a column
I've encountered a problem executing a T-SQL statement (inserting and updating) on linked Oracle servers when executing the query twice.
The first execution works like a charm, but when trying a second time, I get this error:
The OLE DB provider…

mhfmn
- 41
- 5
2
votes
2 answers
Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server
I am trying to query data from linked server. It is giving me the following error:
TNS:listener does not currently know of service requested in connect descriptor".
Msg 7303, Level 16, State 1, Line 4
Cannot initialize the data source object of OLE…

sparklingstar
- 21
- 1
- 1
- 5