Hi Rick, thanks for that. It already helped a lot and I am starting to understand. I successfully wrote my first function reading the value stored on my ID table and returning it. What I can NOT figure out is: you advised that I need to create a function (rather than a procedure) and you stated to use the 'CONTAINS SQL' function element. Actually when I use 'CONTAINS SQL' when defining the function, I am getting an error that I am trying to read data, but have not specified 'READS SQL DATA'. When I change 'CONTAINS SQL' to 'READS SQL DATA' my function works and returns the result. However I need to not only select, but also update the data by incrementing the ID value on the ID table (see the select for update & update in my pgsql sample). But it seems that using a function I can not update data (and the explanation in the derby manual which is given for 'contains data' honestly doesn't make sense to me) and when using a procedure I could update data, but with a procedure not return any value. However I need to update data and return the new value so that I know which ID has been assigned. Can you help with the solution of this please?
Thanks again Thomas