Solved

Delete OPENQUERY Error

Posted on 2013-10-30
7
778 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now