T-SQL How to end an IF-ELSE IF-ELSE block

前端 未结 6 1652
野的像风
野的像风 2021-02-12 10:44

When I run the below procedure with the correct parameters so that the -1 value isn\'t returned, none of my DML statements are firing. I\'m guessing that it\'s treating all my D

6条回答
  •  孤街浪徒
    2021-02-12 11:07

    The last ELSE in your If, ELSE IF, ELSE contains multiple lines of code. You need to start it with BEGIN and end it with END. See this MSDN documentation for more details.

    IF @Code = 'KP'
        SET @stringConcat += 'Y';
    ELSE IF @Code = 'RL'
        SET @stringConcat += 'Z';
    ElSE
        BEGIN
            -- Return error code and stop processing
            SELECT -1;
            RETURN;
        END
    

提交回复
热议问题