SQL Problem with serial
Posted in 2000
Topics: Stored Procedures & SPL
Hello,
I have a problem with the following script:
create procedure insert_firma(.....
define new_part_id integer;
define zeitstempel datetime year to second;
let zeitstempel = current year to second;
insert into partner (part_id, number, date) values(0, 1,zeitstempel);
-- weil Firma -> part_in = 1 !!
select part_id into new_part_id from partner
where part_in = 1 and datum = zeitstempel;
...
The part_id is a serial(datatyp). I must know the new part_id
(automatically generated) after the insert. At the moment the select
(select part_id into ..) provide this, but the problem is, that if two
user call the procedure in one second, the select returns two part_ids.
Can anybody solve this problem?
Thanks a lot.
Harald
Harald Ruf wrote in message <388EB02F.A30FA567@hadiko.de>...
Hello,
I have a problem with the following script:
create procedure insert_firma(.....
define new_part_id integer; define zeitstempel datetime year to second;
let zeitstempel = current year to second;
insert into partner (part_id, number, date) values(0, 1, zeitstempel); -- weil Firma -> part_in = 1 !!
select part_id into new_part_id from partner
where part_in = 1 and datum = zeitstempel;
...
The part_id is a serial(datatyp). I must know the new part_id (automatically generated) after the insert. At the moment the select (select part_id into ..) provide this, but the problem is, that if two user call the procedure in one second, the select returns two part_ids.
Can anybody solve this problem?
Thanks a lot.
Harald
TRY:
create procedure insert_firma(.....
define new_part_id integer; define zeitstempel datetime year to second;
let zeitstempel = current year to second;
insert into partner (part_id, number, date) values(0, 1, zeitstempel); -- weil Firma -> part_in = 1 !!
-- select part_id into new_part_id from partner
-- where part_in = 1 and datum = zeitstempel;
let new_part_id = DBINFO('sqlca.sqlerrd1');
...
The 'sqlca.sqlerrd1' option in DBINFO function returns a single integer that provides the last
serial value inserted into a table IN CURRENT USERS SESSION.
Best regards,
Victor.