Solved

Delete OPENQUERY Error

Posted on 2013-10-30
7
874 Views
Last Modified: 2013-11-05
Hello, I am trying to run the following delete statement:

DELETE OPENQUERY(oraclelinkedserver,'SELECT A.* FROM SCHEMAA.TABLE1 A LEFT JOIN SCHEMAB.TABLE2 B ON A.DODIC = B.DODIC AND B.STATUS = ''C'' WHERE B.DODIC IS NULL')

The linked server is an Oracle 11g server and I am running SQL Server 2008 R2.  

I can do other simple delete openqueries but I can't figure out if its just the join it doesn't like or the naming conventions... I have tried changing the select list to be just the fields from table A but of course it doesn't like that cause the dodic field exists in both tables.

This is the error message:
OLE DB provider "OraOLEDB.Oracle" for linked server "oraclelinkedserver" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
Msg 7345, Level 16, State 1, Line 1

Any ideas?  Thanks!
0
Comment
Question by:Roxanne25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:DcpKing
ID: 39613254
Directly; make sure table1 and table2 have unique indexes, and is schemaa.table1 sufficient, or can you be more "precise"? Rather like using server.database.schema.table in ordinary T-SQL.

Indirectly; write a stored procedure on the Oracle side and run that from the SQL Server side. in the end it might be a lot easier!

hth

Mike
0
 

Author Comment

by:Roxanne25
ID: 39613260
I am unable to make sure they have indexes... I have limited permissions on this Oracle database.  With an openquery, the server is already specified and yes the syntax for the tables is correct.  I can run the exact query as a select statement just not a delete.  

I also would be unable to write a stored procedure in Oracle... The only access I have to these tables is via the linked server or Oracle SQL Plus directly.  They are external tables we are responsible for updating in another system.  

I can also run the delete statement directly in Oracle just fine... I'm assuming it has to do with the capabilities of openquery ...

My only other alternative is to just write it like a normal SQL statement in SQL Server using linkedservername..schema.table but it will be incredibly slow and inefficient.  

:(
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39613265
If "they" (the owners of the other system) are willing to let you delete data from their tables then I would have thought that they would have been delighted to spend 5 minutes or so writing a stored procedure you could run so they would know that you weren't deleting the wrong things!  <grin> !

I'd say ask about the indexes. More than that I don't know - sorry!

Mike
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:Roxanne25
ID: 39613934
You would think so.... ;)  but "they" don't even know how their database works most of the time.  That's the government for ya.... ;)  They ask me a lot of the time how stuff works and I always have to tell them if they have a data load that failed (cause the table is empty or something) and then they are like ummmm ... which table?  *eyeroll*
0
 

Accepted Solution

by:
Roxanne25 earned 0 total points
ID: 39614117
Well, I guess I fixed it .... its not what I wanted but at least it works.  I changed the query so its not a join and uses a not in (select) instead.

delete openquery(linkedserver, 'select * FROM table1
WHERE dodic not in (select dodic from table2
where table2.dodic is not null and table2.status not in ('T', 'H', 'Q'))')

So, I guess openqueries just can't perform joins in a delete statement.

Thank you for trying to help though. :)
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39614353
Ok. Thanks for telling us all the answer you found, so others can benefit!
0
 

Author Closing Comment

by:Roxanne25
ID: 39623766
Changed the syntax of my query and resolved the issue.  Was not ideal, but solved the problem myself.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question