View Single Post

   
  #2 (permalink)  
Old 02-27-2008, 02:06 PM
Lennart
 
Posts: n/a
Default Re: Yet another query question...

On Sep 26, 1:42 am, shorti <lbrya...@juno.com> wrote:
> I am inserting a record into a table that has an identity column that
> does a GENERATED ALWAYS. It is the only column in the table that
> gives the record its uniqueness. I want to capture this number when I
> insert a record. How can I do it in one step?
>
> I found this query in the DB2 Info Center. It does some other things
> but I tried to convert it to what I needed and couldnt get it to
> work. Here is the Info Center query:
>
> SELECT inorder.ordernum
> FROM (INSERT INTO orders(custno)INCLUDE (insertnum integer)
> VALUES(:cnum1, 1), (:cnum2, 2)) InsertedOrders
> ORDER BY insertnum;
>


I'm not sure I undestand your sql, but something along the lines of:

SELECT InsertedOrders.ordernum
FROM new table (
INSERT INTO orders(custno)
VALUES(:cnum1), (:cnum2)
) InsertedOrders (ordernum, custno)
ORDER BY insertnum;


/Lennart


Reply With Quote