Hi lloyd,
I think there is some confusion, with regard to serial datatype and its manipulation. While inserting a row in a table having serial datatype field, one need to pass 0 (zero) as a place holder for the data, in order to generate the sequence number by the database server.
Demo Customer table definition:
create table customer
(
customer_num serial(101),
fname char(15),
lname char(15),
company char(20),
address1 char(20),
address2 char(20),
city char(15),
state char(2),
zipcode char(5),
phone char(18),
primary key (customer_num)
);
Insert Statement Example:
INSERT INTO customer VALUES (0,'Ravi','Kumar','ABC Ltd', '213, SV Road', 'Santacruz West', 'Mumbai', 'MH', '054', '091-022-1234');
To know the customer number generated for the above insert statement you may execute SQL:
SELECT DBINFO('sqlca.sqlerrd1') FROM systables WHERE tabid=1 ;
The above select statement is equivalent to SP:
CREATE PROCEDURE GetSerialNumber() RETURNING integer;
RETURN DBINFO('sqlca.sqlerrd1');
END PROCEDURE
To call the above SP execute SQL:
EXECUTE PROCEDURE GetSerialNumber()
Regards,
Shriyan
"Man who knows, knows, he knows nothing!"