0

当我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
4

1 回答 1

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
于 2013-07-18T17:03:22.477 回答