Link to home
Start Free TrialLog in
Avatar of philosullivan
philosullivan

asked on

Stored Procedure Using LAST_INSERT_ID()

Im trying to use LAST_INSERT_ID() as variable in a stored procedure
after the first insert statment is run i want to return the id of the last auto inc record and then use that value in the second insert statement.
attached is my current procedure it returns the following error:
Unknown column 'NewLockID' in 'field list'




CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_LockAdd`(
IN LockSerial VarChar(50),
IN LockDescription VarChar(50),
IN LockAssetID VarChar(50),
IN LockName VarChar(50),
IN LockLabelID VarChar(45),
IN LockAdded VarChar(45),
IN LockAddedBy VarChar(45),
IN LockStreet VarChar(45),
IN LockCity VarChar(45),
IN LockState VarChar(45),
IN LockZip VarChar(45),
IN LockCountry VarChar(45),
IN RouteID INT (11))
BEGIN
INSERT INTO esc.tbllocks (fldIDElectronic,fldDescription,fldAssetID,fldName,fldIDLabel,fldadded,fldaddedby,fldaddress1,fldcity,fldstate,fldzip,fldcountry) VALUES
(LockSerial,LockDescription,LockAssetID,LockName,LockLabelID,LockAdded,LockAddedBy,LockStreet,LockCity,LockState,LockZip,LockCountry);
SELECT LAST_INSERT_ID() as NewLockID;
INSERT INTO tblroutestolocks (fldLockID,fldRouteID) VALUES
(NewLockID,RouteID);
END

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of philosullivan
philosullivan

ASKER

awsome, thanks! i see what i was doing wrong.