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 > Query Help Please...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-04, 10:36
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
Unhappy Query Help Please...

I am trying to update some values in a table based on a translation table that I have built. I have tried two queries, one whose syntax will not work, and one with undesirable effects.

1)
UPDATE DEVDTA.LN_LEASERECORD
SET DOCO = PRODDTA.TBL_LEASECOPY.NEWDOCO
WHERE DEVDTA.LN_LEASERECORD.DOCO = PRODDTA.TBL_LEASECOPY.OLDDOCO;

This is exactly what I would like the query to do...it is pretty self expanatory...however PRODDTA.TBL_LEASECOPY.NEWDOCO errors out as an undefined column.

2)
UPDATE DEVDTA.LN_LEASERECORD
SET DOCO = (SELECT NEWDOCO FROM PRODDTA.TBL_LEASECOPY WHERE PRODDTA.TBL_LEASECOPY.OLDDOCO = DEVDTA.LN_LEASERECORD.DOCO);

This runs however where the select by itself only selects matching records, in the update query, the 226 matching records are correctly updated will 8900+ records are changed to null.

Can anyone tell me what I need to do differently?

Thanks in advance.

Ryan Hunt
Reply With Quote
  #2 (permalink)  
Old 07-07-04, 10:58
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Try adding
WHERE DEVDTA.LN_LEASERECORD.DOCO IN (SELECT OLDDOCO FROM PRODDTA.TBL_LEASECOPY)
Reply With Quote
  #3 (permalink)  
Old 07-07-04, 14:09
dsusendran dsusendran is offline
Registered User
 
Join Date: Apr 2004
Location: Inside Intel
Posts: 165
Lightbulb

Reply With Quote
  #4 (permalink)  
Old 07-07-04, 14:45
AS400Admin AS400Admin is offline
Registered User
 
Join Date: Aug 2003
Posts: 39
That was simple...I feel rather silly...

Thanks. RH
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