I have the following stored procedure:
BEGIN
insert into Timesheet (TS_ORID, TS_Begin, TS_End, TS_Hourrate, TS_PRID, TS_Desc, TS_OldID, TS_USID)
values (ORID, BeginT, EndT, Hourrate, PRID, Description, OldID, USID);
set TS_ID = LAST_INSERT_ID();
END
TS_ID is a Output parameter.
I call this procedure in a SQLInsert part and that works. However it will not put the TS_ID into the identity field of the component, how can I do this?
SQLInsert
-
AndreyZ
If you use the INSERT statement in SQLInsert the identity column will be automatically filled. For that you have to put the following SQL code to SQLInsert:
And if you want to use stored procedure in SQLInsert, then you will have to set the identity column manually. You can get the LAST_INSERT_ID value using the following code:
Code: Select all
insert into Timesheet (TS_ORID, TS_Begin, TS_End, TS_Hourrate, TS_PRID, TS_Desc, TS_OldID, TS_USID)
values (ORID, BeginT, EndT, Hourrate, PRID, Description, OldID, USID);Code: Select all
MyQuery.SQL.Text := 'SELECT LAST_INSERT_ID() as ID;';
MyQuery.Open;
ID := MyQuery.FieldByName('ID').AsInteger;-
AndreyZ