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 > Error with IDENTITY_VAL_LOCAL()

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-28-04, 22:29
chunglun chunglun is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
Error with IDENTITY_VAL_LOCAL()

Hi,

I am using DB2 UDB ESE 8.1.5 on a win2000 server.
I tried to use the function IDENTITY_VAL_LOCAL to get the most
up-to-date record with following statement:

VALUES IDENTITY_VAL_LOCAL() INTO :IVAR

in the command center, but it prompt me for the below message:
CLI0100E Wrong number of parameters. SQLSTATE=07001

I've already turned off the auto commit. Could anyone can give me a
helping hand, please? Many thanks!

And also, if I want to use the same function for programming with C#
.NET, by using OLEDB provider, should I bear anything in mind?

Regards,
Chunglun
Reply With Quote
  #2 (permalink)  
Old 04-29-04, 08:36
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by chunglun
Hi,

I am using DB2 UDB ESE 8.1.5 on a win2000 server.
I tried to use the function IDENTITY_VAL_LOCAL to get the most
up-to-date record with following statement:

VALUES IDENTITY_VAL_LOCAL() INTO :IVAR

in the command center, but it prompt me for the below message:
CLI0100E Wrong number of parameters. SQLSTATE=07001
The Command Center won't take parameters like that...

Just use "values identity_val_local()"
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 04-29-04, 23:13
chunglun chunglun is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
I also tried just using VALUES IDENTITY_VAL_LOCAL(), but it returned a table with nothing to me. I can't get the identity that I want.

Actually, I just want to make sure I can get the past inserted identity while programming with C#. Anyone has idea? Thanks!

Chunglun
Reply With Quote
  #4 (permalink)  
Old 04-30-04, 02:49
hurmavi hurmavi is offline
Registered User
 
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
SELECT MAX(key) FROM TABLE;
With this, you can't go too low.

Another way is to make an insert AND only then IDENTITY_VAL_LOCAL() will return a value.

Cheers, Bill
Reply With Quote
  #5 (permalink)  
Old 04-30-04, 07:58
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Quote:
Originally Posted by chunglun
I also tried just using VALUES IDENTITY_VAL_LOCAL(), but it returned a table with nothing to me. I can't get the identity that I want.

Actually, I just want to make sure I can get the past inserted identity while programming with C#. Anyone has idea? Thanks!

Chunglun
That should work, assuming you did an insert immediately before into a table with a column defined as IDENTITY, and that you didn't supply a value for that column.

MAX() is dangerous as someone may have inserted another row in that split second before you get the value... and it can be expensive if the column is not in an index defined for reverse scans or DESC.
__________________
--
Jonathan Petruk
DB2 Database Consultant
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