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 > updating cols with sequence objects

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-11, 14:29
johnson55 johnson55 is offline
Registered User
 
Join Date: Apr 2011
Posts: 4
updating cols with sequence objects

I have the following sql

UPDATE TABLEA
SET COL1 =
CASE COL2
WHEN 'A' THEN NEXTVAL FOR SEQUENCEA
WHEN 'B' THEN NEXTVAL FOR SEQUENCEB
END
WHERE COL3 = 1

I get the following error:

>[Error] Script lines: 1-10 -------------------------
DB2 SQL error: SQLCODE: -348, SQLSTATE: 428F9, SQLERRMC: NEXTVAL
Message: "NEXTVAL" cannot be specified in this context. 


Do I need to put the next val in a variable before updating?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 04-26-11, 15:17
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
SQL0348N is the error message corresponding to SQLCODE -348. That message says: SQL0348N
Quote:
NEXT VALUE expressions cannot be specified in the following contexts:

* CASE expression
* ...
So you have to change your statement so that NEXTVAL is not used inside the case expression. You could try to wrap it into a SELECT (untested):
Code:
UPDATE ...
SET ... = ( SELECT NEXTVAL FOR sequencea FROM sysibm.sysdummy1 WHERE col2 = 'A' ) UNION ALL ( SELECT NEXTVAL FOR sequenceb FROM sysibm.sysdummy1 WHERE col2 = 'B' )
WHERE col3 = 1
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 04-26-11, 16:12
johnson55 johnson55 is offline
Registered User
 
Join Date: Apr 2011
Posts: 4
great thanks!!
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