-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Update not working
PostPosted: Fri Dec 07, 2007 6:10 pm 
Regular
Regular

Joined: Wed Sep 29, 2004 11:34 am
Posts: 62
Location: Houston, TX
Hello all I have a very simple update that I need to do, but it requires me to make a join on another table or two:

Here is an query that I had initially but that gave me an error

update Quote q, Employee e set q.EmployeeID = null where q.EmployeeID = e.Id and q.EmployeeID is not null and q.IsProcessed = 0 and e.Department.Id IN (1,2)

This gives me an error stating that "Expected set, but found "," - That is pointing to my reference to the table Employee

Then I decided to alter it by calling createSQLQuery by using native SQL:

update quote q, employee e set q.EmployeeID = null where q.EmployeeID = e.Id and q.EmployeeID is not null and q.IsProcessed = 0 and e.Department IN (1,2)

That gave me an MySQL Exception error by stating that there is no table named "Quote" - that is true because in the database the table "quote" is all lowercase.

I would like to basically do a very simple update - how can I go about creating an update statement that works?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Update not working
PostPosted: Fri Dec 07, 2007 6:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
dawuad wrote:
Hello all I have a very simple update that I need to do, but it requires me to make a join on another table or two:

Here is an query that I had initially but that gave me an error

update Quote q, Employee e set q.EmployeeID = null where q.EmployeeID = e.Id and q.EmployeeID is not null and q.IsProcessed = 0 and e.Department.Id IN (1,2)

This gives me an error stating that "Expected set, but found "," - That is pointing to my reference to the table Employee

Then I decided to alter it by calling createSQLQuery by using native SQL:

update quote q, employee e set q.EmployeeID = null where q.EmployeeID = e.Id and q.EmployeeID is not null and q.IsProcessed = 0 and e.Department IN (1,2)

That gave me an MySQL Exception error by stating that there is no table named "Quote" - that is true because in the database the table "quote" is all lowercase.

I would like to basically do a very simple update - how can I go about creating an update statement that works?

Thanks in advance.


How about this?

Code:
update Quote q set q.EmployeeID = null
where q.EmployeeID is not null and q.IsProcessed = 0 and
q.EmployeeID in ( select e.id from Employee e where e.Department.Id IN (1,2) )


You may also want to fiddle around with the nested select to have a better performance.

Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.