我無法弄清下列查詢語法錯誤。幫助?幫幫我 ?幫幫我 ?語法錯誤在MYSQL'1064'
CREATE PROCEDURE VoucherNumberGenerationForClass(
p_voucherType varchar(50),
p_yearId varchar(50),
p_NO longtext)
begin
IF((SELECT COUNT(suffixPrefixId)FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType))<>0)
then
DECLARE p_prefix VARCHAR(50);
DECLARE p_startIndex int ;
DECLARE p_suffix VARCHAR(50) ;
DECLARE p_voucherNo VARCHAR(50) ;
DECLARE p_prefix1 VARCHAR(50) ;
DECLARE p_suffix1 VARCHAR(50) ;
IF (((SELECT COUNT(suffixPrefixId)FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType)))<>0);
then
SET p_prefix=(SELECT ifnull(prefix,'') FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType));
SET p_suffix=(SELECT ifnull(suffix,'') FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType));
SET p_startIndex=(SELECT startIndex FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType));
SET p_startIndex=p_startIndex-1;
IF p_voucherType='Sales Invoice'
then SET p_voucherNo=(SELECT ifnull(MAX(voucherNo+1),1) FROM tbl_SalesMaster WHERE((suffixPrefixId = (SELECT suffixPrefixId FROM tbl_SuffixPrefix WHERE (yearId = p_yearId) AND (voucherType = p_voucherType)))
))
END if ;
SET p_voucherNo=p_voucherNo+p_startIndex ;
SET p_voucherNo= p_prefix+ p_voucherNo+p_suffix ;
SELECT p_voucherNo ;
END if;
ELSEIF
IF p_voucherType='Sales Invoice'
then SET p_voucherNo=(SELECT ifnull(MAX(voucherNo+1), 1) FROM tbl_SalesMaster) ;
SELECT p_voucherNo ;
END IF ;
end ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLA RE p_prefix VARCHAR(50); DECLARE p_startIndex int ; DECLARE p_suffix VARCHA' at line 8
我想你需要'ELSEIF'中的空間。像這樣'ELSE IF' – Nithesh
ELSE IF在mssql而不是mysql中。 mysql has ELSEIF – Nisar
爲什麼geven我-2;( – Nisar