CREATE PROCEDURE:mysql语法错误

时间:2013-07-18 16:37:57

标签: mysql procedure

DELCARE @qty INT时出现语法错误,因为SET qty = ...AND q = @qty

我不知道如何纠正这些语法错误!

这里的程序:

CREATE PROCEDURE test(target INT)
BEGIN

    DECLARE qty INT

    -- Get closest qty
    @qty = SELECT q
            FROM MH
            ORDER BY ABS(@target - q) ASC
            LIMIT 1


    -- use that "actual" qty in your query
    SELECT  ((p+m)*((valore+100)/100))
    FROM    PL
    JOIN    TV
    JOIN    MH
    WHERE   Date = '20130717'
    AND     End = ''
    AND     q = @qty

END

1 个答案:

答案 0 :(得分:0)

CREATE PROCEDURE test(target INT)
BEGIN

DECLARE qty INT default 0;

SELECT q into qty
        FROM MH
        ORDER BY ABS(target - q) ASC
        Limit 1;
SELECT  ((p+m)*((valore+100)/100))
FROM    PL
JOIN    TV
JOIN    MH
WHERE   Date = '2013/07/17'
AND     End = ''
AND     q = qty;

END