File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating multiple tables in one sql query

 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am writing a sql query where I want to update 2 tables in one query as this:

UPDATE table1 as t1, table2 as t2 SET t1.UpdateFlag = 'N', t2.UpdateFlag = 'N' where t1.IdNumber = t2.IdNumber and t1.UpdateFlag = 'T' and t2.UpdateFlag = 'T'

It is not working, please help how to proceed.

Thanks,
Luke.
 
saurav sarkar
Ranch Hand
Posts: 180
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the error you get?
 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saurav,

Thanks for the reply, here is the error:

"Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'as'."

I am using MS query analyzer. This error does not help me much. Any suggestions.

Thanks,
Luke.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I am aware, you can't update two tables with one update statement. Someone might tell me I'm wrong here, but I think your only choices are two update statements or stored procedure.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul for the information.
Luke.
 
Nick Bruns
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be done,

http://www.christonium.com/SearchEngineMarketing/ItemID=11936974368828

That's with MySQL though. But sorry I don't know what's wrong with your query...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic