这段代码中有一些错误,尝试调试但找不到答案。
有人可以纠正我吗?
BEGIN
DECLARE FINALID VARCHAR(8);
DECLARE MAXIDCOMPANY VARCHAR(8);
SELECT MAX(SUBSTRING(company.idCompany,3,8))+1 INTO MAXIDCOMPANY
FROM company
WHERE SUBSTRING(company.idCompany,1,2) = SUBSTRING(nmCompany,1,2);
IF MAXIDCOMPANY > 0 AND MAXIDCOMPANY < 10 THEN
SET FINALID = CONCAT(SUBSTRING(nmCompany,1,2),'00', CONVERT(MAXIDCOMPANY USING latin1));
ELSEIF MAXIDCOMPANY > 9 AND MAXIDCOMPANY < 100 THEN
SET FINALID = CONCAT(SUBSTRING(nmCompany,1,2),'0', CONVERT(MAXIDCOMPANY USING latin1));
ELSEIF MAXIDCOMPANY > 99 THEN
SET FINALID = CONCAT(SUBSTRING(nmCompany,1,2), CONVERT(MAXIDCOMPANY USING latin1));
END IF;
IF MAXIDCOMPANY IS NULL THEN
SET FINALID = CONCAT(SUBSTRING(nmCompany,1,2),'001');
END IF;
INSERT INTO company
(company.idCompany, company.nmCompany, company.country, company.address, company.region, company.joinDate, company.quota, company.createdUser, company.createdDate, company.updatedUser, company.updatedDate)
VALUES
(FINALID, nmCompany, country, address, region, joinDate, quota, createdUser, NOW(), updatedUser, updatedDate);
END
那是代码,程序在接近 1000 之后卡在计数器上。
例子 :
当我将例如 IN1000 的数据添加为 idCompany 时,它总是停留在那个数字上,但是当我查询最大数据时它只显示 IN999,为什么不是 IN1000
非常感谢