Solved

Delete OPENQUERY Error

Posted on 2013-10-30
7
837 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
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
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.

733 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