Hi all, I am new to MYSQL but not to databases, I am used to SQL Server..
My problem is I have written an SP that inserts a new record from C#. The SP does not return the correct ID column? It returns an ID from the previously run SP. The previously run SP inserts a user and that ID is then picked up in this SP. The value returned is the UserID from LAST_INSERT_ID()? An thoughts?
Thanks in advance. The culprit is below
Age is a consequence of experience
My problem is I have written an SP that inserts a new record from C#. The SP does not return the correct ID column? It returns an ID from the previously run SP. The previously run SP inserts a user and that ID is then picked up in this SP. The value returned is the UserID from LAST_INSERT_ID()? An thoughts?
Thanks in advance. The culprit is below
Code:
DELIMITER $$
CREATE PROCEDURE AMCompanySave
(
pCompanyName VARCHAR(50),
pUserCompanyHash VARCHAR(40),
pUserHash VARCHAR(40),
pCompanyNumber VARCHAR(15),
pVatNo VARCHAR(30)
)
BEGIN
declare retCompanyID int;
SELECT @pAMUserID := AMUserID FROM AMUsers WHERE PasswordHash = pUserHash;
INSERT INTO UserCompanies (UserCompanyName, AMUserID, CompanyNameHash, CompanyNumber, VatNo, DateAdded)
VALUES (pCompanyName, @pAMUserID, pUserCompanyHash, pCompanyNumber , pVatNo, NOW() );
SET retCompanyID = LAST_INSERT_ID();
select retCompanyID;
END $$
DELIMITER ;
Age is a consequence of experience