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 > PROBLEM using INDENTITY_VAL_LOCAL() function with sub queries in VALUES clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-16-07, 06:11
Selvaprabhu Selvaprabhu is offline
Registered User
 
Join Date: Mar 2007
Posts: 1
Question PROBLEM using INDENTITY_VAL_LOCAL() function with sub queries in VALUES clause

Hi All,

Greetings!!!

I'm very new to this group and i'm facing a problem with using INDENTITY_VAL_LOCAL() function to get the last value of the identity column. The function returns null when i use sub queries (SELECTs) in the VALUES clause. For example, running the following sqls return the correct value of the identity column.

INSERT INTO table2(column2, column3) VALUES('value1','value2');

SELECT IDENTITY_VAL_LOCAL() as LastCreatedValue, COUNT(*) as dummy from table2;

However, the IDENTITY_VAL_LOCAL() function returns null if i use SELECT in the VALUES clause.

INSERT INTO table2(column2, column3) VALUES((SELECT column1 FROM table1 WHERE column2='TEST'),'value2');

SELECT IDENTITY_VAL_LOCAL() as LastCreatedValue, COUNT(*) as dummy from table2;

I'm using DB2 8.1.14 version. Can anyone tell me what the problem may be?
Reply With Quote
  #2 (permalink)  
Old 03-16-07, 16:27
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I don't know the answer to your question, but why don't you simply select the results of your INSERT operation? This will work with your subselect as well.
Code:
SELECT id
FROM   NEW TABLE ( INSERT INTO table2(column2, column3) VALUES ( ... ) ) AS t(id, column2, column3)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 03-19-07, 14:23
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Refere the manual ... There are a number of cases when the function will not work ... IIRC, your case is also documented.

As you are FP9+, you should be using Knut's suggestion

Sathyaram
__________________
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