我想執行下面的存儲過程,但它給了我一個錯誤。更新訂單表後,在標誌1內我想檢查另一個條件,如果這是真的,那麼我想運行另一個更新查詢。我在SQL Server中用臨時表試過了,它工作正常。請幫幫我。在MySQL中嵌套IF ELSE
誤差如下:
腳本行:4您的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法使用 接近手動 「從產品PR INNER JOIN(SELECT PR.ID AS產品ID,(PR.Quantity - OD.Qu」在第35行
DELIMITER $$
DROP PROCEDURE IF EXISTS `onlineshop`.`USP_Public_SaveOrder` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `USP_Public_SaveOrder`(IN pint_Flag INT,INOUT pint_ID BIGINT,IN pint_Status INT,IN pint_CustomerID BIGINT,IN pint_ShippingAddressID BIGINT,IN pint_BillingAddresID BIGINT, IN pdec_ShippingCharge DECIMAL(18,2),IN pdec_Tax DECIMAL(18,2),IN pdec_Total DECIMAL(18,2),IN pdte_TransactionDate DATETIME)
BEGIN
IF(pint_Flag=0) THEN
INSERT INTO orderheader(Status,
CustomerID,
ShippingAddressID,
BillingAddressID,
ShippingCharge,
Tax,
Total,
TransactionDate)
VALUES (pint_Status,
pint_CustomerID,
pint_ShippingAddressID,
pint_BillingAddresID,
pdec_ShippingCharge,
pdec_Tax,
pdec_Total,
pdte_TransactionDate);
SET pint_ID=LAST_INSERT_ID();
ELSEIF(pint_Flag=1) THEN
UPDATE orderheader
SET Status = pint_Status,
CustomerID = pint_CustomerID,
ShippingAddressID = pint_ShippingAddressID,
BillingAddressID = pint_BillingAddresID,
ShippingCharge = pdec_ShippingCharge,
Tax = pdec_Tax,
Total = pdec_Total,
TransactionDate = pdte_TransactionDate
WHERE ID=pint_ID;
IF(pint_Status=2) THEN
UPDATE product SET Quantity = A.remain
FROM product PR
INNER JOIN (SELECT PR.ID AS ProductID, (PR.Quantity - OD.Quantity) AS remain
FROM product P
INNER JOIN orderdetail OD ON OD.ProductID = P.ID AND OD.OrderID = pint_ID) A ON PR.ID = A.ProductID
ELSE
RETURN
END IF;
END IF;
END $$
DELIMITER ;
你似乎在最後一個「ELSE」之前缺少一個分號。 – Jocelyn
我添加了一個分號。但仍然得到相同的錯誤 – user2837480