Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 1252
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: 1827
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 ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts SIGNAL ON HALT issue packerm CLIST & REXX 1 Fri Oct 20, 2017 6:56 pm
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us