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 > Better update...?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-05-04, 11:21
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
Question Better update...?

Is there a better solution to the one I found for this UPDATE statment?

UPDATE MyTable CF SET (CF.OrgId, CF.G_OrgId, CF.Status, TimeModified) =
(SELECT CT.BOrgId,CT.BGOrgId, CASE CT.BGOrgId WHEN '' THEN 302 ELSE 303 END, CURRENT TIMESTAMP FROM SESSION.My_Temp CT WHERE CT.Id = CF.Id AND CT.Operation = 'RUN')
WHERE CF.Id IN (SELECT CT.Id FROM SESSION.My_Temp CT WHERE CT.Id = CF.Id AND CT.Operation = 'RUN')

Basically I'm updated a table based on a values from a temp table. The target table can only be updated if the temp table values contain the target table ids.

This works but it seems silly to have to duplicate my select in order to achieve this. Is there a way to do an inner join on a select?
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