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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-09, 09:50
mac4rfree mac4rfree is offline
Registered User
 
Join Date: Jul 2009
Posts: 52
query help

Hello Guys,,

This is my first post here...

Actually i like to update a column from table A with a value from table B on some
conditions. The query is as follows:

update krms_Stg.SVHC_RAWTREESTRUCTUREDATAFORALL a
set a.Wt_Fatherid =
(select a1.value
from krms_Stg.RAWTREESTRUCTUREDATAFORALL a1
where a1.NODEID_FATHER=a.NODEID_SON and
a1.TOP_LEVEL_NODE_ID=a.TOP_LEVEL_NODE_ID)
where a.TOP_LEVEL_NODE_ID=a1.TOP_LEVEL_NODE_ID and
a.NODEID_SON=a1.NODEID_SON and
a.NODEID_FATHER=a1.NODEID_FATHER;

But it is throwing an error saying the alias A1 is not recognized.

Please help me out of this..

Thanks for your help in advance,,

Regards,
Magesh.
Reply With Quote
  #2 (permalink)  
Old 07-16-09, 10:34
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
MERGE statement may help you.
Like this:

merge into krms_Stg.SVHC_RAWTREESTRUCTUREDATAFORALL a
using krms_Stg.RAWTREESTRUCTUREDATAFORALL a1
on a1.NODEID_FATHER = a.NODEID_SON
and a1.TOP_LEVEL_NODE_ID = a.TOP_LEVEL_NODE_ID
when matched then
update set a.Wt_Fatherid = a1.value
;
Reply With Quote
  #3 (permalink)  
Old 07-16-09, 10:38
mac4rfree mac4rfree is offline
Registered User
 
Join Date: Jul 2009
Posts: 52
Thanks tonkuma... But still am having a problem..
Am getting this error..
SQL0788N The same row of target table "KRMS_STG.SVHC_RAWTREESTRUCTUREDATAFORALL" was identified more than once for an update, delete or insert operation of the MERGE statement. SQLSTATE=21506
Reply With Quote
  #4 (permalink)  
Old 07-16-09, 12:34
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Doesn't
Code:
a1.NODEID_FATHER = a.NODEID_SON
and a1.TOP_LEVEL_NODE_ID = a.TOP_LEVEL_NODE_ID
identify a unique record ????

IIRC, it has to - otherwise you get this message
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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