Re: Insert a return a Serial Column Value
Posted in 2004
Dan,
If you create a SERIAL column in your table, and then insert 0 into
that column, this will generate a serial number. You can then use
db_info() to find out the value that was inserted by an insert
statement.
I added a serial column to your table, modified your insert statement
to reflect that change and performed a select after the insert that
will return the serial number you just inserted. So this will return
"1" but subsequent runs of the insert and select will show 2,3,4 etc.
I hope this does what you want.
CREATE TABLE scheduler
(id_no SERIAL , creator_ds CHAR(10),location_ds CHAR(10), start_dt DATE);
INSERT INTO scheduler
(id_no, creator_ds, location_ds, start_dt )
VALUES (0, "testid","home","07/07/2004");
SELECT dbinfo("sqlca.sqlerrd1") FROM systables
WHERE tabname = "scheduler";
webmaster@sharperweb.com (Dan) wrote in message news:<bbac90ba.0407071321.2c2b8a39@posting.google.com>...
> I am trying to insert a record and return a serial column named id_no
> expecting the following query to give me what I am looking for, but
> without any luck(this produces error). I need to keep this as simple
> as possible and avoid having a stored procedure. Can someone help
> edit this query or point me to a complete example.
>
> INSERT INTO scheduler
> (creator_ds, location_ds, start_dt )
> VALUES ("testid","home","07/07/2004")
> returning id_no;>
> Thanks ahead
> Dan