Re: Stored procedure problems
Posted in 1996
See my comment in your code: Roger Hernandez wrote: } } I am trying to create stored procedure which will insert a row into a } table which has a serial column, and will return me the generated values } by using DBINFO. Any ideas why its not working (its returing a huge } negative number)?: } } CREATE PROCEDURE sp_prov_srvc (p_sub_id INT, p_srvc_typ INT, p_ct_typ } INT) } RETURNING INT; } } DEFINE r_last_serial INT; } } INSERT INTO wasabi.v_srvc (sub_id, srvc_typ) } VALUES (p_sub_id, p_srvc_typ); If you insert any serial value in this statement, you should insert '0' to the serial column. The actual value will be generated by the system. It seems you assign a value to it. } } SELECT DBINFO ('sqlca.sqlerrd1'), COUNT (*) } INTO r_last_serial } FROM wasabi.v_srvc; Where do you store count value? try SELECT UNIQUE dbinfo('sqlca.sqlerrd1'), COUNT(*) INTO last_serial, some_count FROM v_srvc; } } INSERT INTO wasabi.v_srvc_ct (srvc_id, srvc_typ, ct_typ) } VALUES (r_last_serial, p_srvc_typ, p_ct_typ); } } RETURN r_last_serial; } END PROCEDURE; Weimin Yang