Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Issue while using MERGE to Update a table in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
GaganGarg

Active User


Joined: 31 Mar 2010
Posts: 134
Location: India

PostPosted: Wed Aug 06, 2014 2:16 pm    Post subject: Issue while using MERGE to Update a table in DB2
Reply with quote

HI,
I m trying to update a table using MERGE in DB2 query.
Query looks like as given below:

Code:

    MERGE INTO AMTTABLE A                                           
  USING (SELECT CTRY_CODE,CO_CODE, ITEM_ID, AMT FROM AMTTABLE) B
   ON ( B.CTRY_CODE   = A.CTRY_CODE                                   
      AND B.CO_CODE   = A.CO_CODE                                     
      AND B.ITEM_ID   = A.ITEM_ID )                                   
     WHEN MATCHED   
      AND B.AMT   <> A.AMT                                     
                  THEN UPDATE SET A.AMT = B.AMT       
                  WHEN NOT MATCHED THEN                               
                       SIGNAL SQLSTATE '70002'                       



I'm getting following sql error:

Code:

---------+---------+---------+---------+---------+---------+---------+---------+
DSNT408I SQLCODE = -199, ERROR:  ILLEGAL USE OF KEYWORD SELECT.  TOKEN VALUES   
         WAS EXPECTED                                                           
DSNT418I SQLSTATE   = 42601 SQLSTATE RETURN CODE                               
DSNT415I SQLERRP    = DSNHPARS SQL PROCEDURE DETECTING ERROR                   
DSNT416I SQLERRD    = 2 0  0  -1  80  506 SQL DIAGNOSTIC INFORMATION           
DSNT416I SQLERRD    = X'00000002'  X'00000000'  X'00000000'  X'FFFFFFFF'       
         X'00000050'  X'000001FA' SQL DIAGNOSTIC INFORMATION                   


Db2 version used is 10.1.

Can anybody help me please to identify the issue? Thank you
Back to top
View user's profile Send private message

Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1228
Location: Israel

PostPosted: Wed Aug 06, 2014 7:56 pm    Post subject:
Reply with quote

I think that, in your case, you could just use an UPDATE to update the table...
But it seems you want to change all AMT values to one unique value for all rows having same CTRY_CODE, CO_CODE and ITEM_ID.
Is that what you really want to do ?
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1696
Location: NY,USA

PostPosted: Thu Aug 07, 2014 12:27 am    Post subject:
Reply with quote

Gagan, The feature that you have tried might not be supported by DB2 on ZOS(Check with DBA) but it works perfectly fine over Linux. However, over ZOS supports USING (VALUES... as I tested.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us