If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Can I use Update usin WITH <tab> AS

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-22-09, 14:37
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Can I use Update usin WITH <tab> AS

Hi guys,


some times I use WITH as

Code:
with tmp (name,work) as ( select empno,job from employee) select * from tmp ;
I am wondring how can I update a table by using contents of temprary table.


e.g

Code:
with tmp (name,work) as ( select empno,job from employee) update xyz 
                     set lname= (select name from tmp fetch first 1 row only) ;

I haven't seen any example like this , but there must be some way to do it.

DB2 is pointing an error on update.

I tried to search documentation, but did not find any example using WITH and UPDATE together.

Please help.

DBFinder
Reply With Quote
  #2 (permalink)  
Old 07-22-09, 14:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Try the MERGE statement.
Reply With Quote
  #3 (permalink)  
Old 07-22-09, 16:29
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Actully developer has written a SQL with update.

Do I have to tell him to use MERGE instead of UPDATE.

I can try MERGE for simple example with no problem.
Reply With Quote
  #4 (permalink)  
Old 07-22-09, 16:51
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by DBFinder

Do I have to tell him to use MERGE instead of UPDATE.
I think you should tell him to go read a manual.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On