在MySql存储过程中使用IF和Concat时卡住

在MySql存储过程中使用IF和Concat时卡住,mysql,stored-procedures,Mysql,Stored Procedures,我试图使用IF以及MySql存储过程中的其他代码,但事情似乎不正常,我无法保存存储过程。如果我删除,如果一切正常,我就能保存存储过程 问题在于其中的IF。你能帮忙吗 错误 /* SQL Error (1064): 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 'IF FIND_

我试图使用
IF
以及
MySql
存储过程中的其他代码,但事情似乎不正常,我无法保存存储过程。如果我删除
,如果
一切正常,我就能保存存储过程

问题在于其中的
IF
。你能帮忙吗

错误

/* SQL Error (1064): 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 'IF FIND_IN_SET (10,vals) THEN
                'Grey Link'
            ELSE
                SET ret_val = 'Blue' at line 20 */
存储过程

BEGIN

DECLARE vals VARCHAR(2400);
DECLARE ret_val VARCHAR(2400);

select group_concat(elmAction) into vals from reports where id = this_id and userId = this_user;

SET ret_val = CASE this_id
    WHEN 1 THEN CONCAT (
        'Blue Type 1'
        'Blue Type 2'
        'Blue Type 3' #Here is where the problem is...
            IF FIND_IN_SET (10,vals) THEN
                'Grey Link'
            ELSE
                'Blue link'
            END IF;
        )
ELSE 'Error'
END;


RETURN (ret_val);

END
试试这个:

CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3',
        IF( FIND_IN_SET (10,vals), 'Grey Link','Blue link')
)
使用
案例

CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3',
        CASE
            WHEN FIND_IN_SET (10,vals) = 0 THEN 'Blue link'
            WHEN FIND_IN_SET (10,vals) = 1 THEN ....
            WHEN FIND_IN_SET (10,vals) = 2 THEN ....
        ELSE
            ...
        END
)
试试这个:

CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3',
        IF( FIND_IN_SET (10,vals), 'Grey Link','Blue link')
)
使用
案例

CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3',
        CASE
            WHEN FIND_IN_SET (10,vals) = 0 THEN 'Blue link'
            WHEN FIND_IN_SET (10,vals) = 1 THEN ....
            WHEN FIND_IN_SET (10,vals) = 2 THEN ....
        ELSE
            ...
        END
)
使用案例

    SET ret_val = CASE this_id
    WHEN 1 THEN CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3', 
            case when FIND_IN_SET (10,vals) THEN
                'Grey Link'
            ELSE
                'Blue link'
            END
        )
使用案例

    SET ret_val = CASE this_id
    WHEN 1 THEN CONCAT (
        'Blue Type 1',
        'Blue Type 2',
        'Blue Type 3', 
            case when FIND_IN_SET (10,vals) THEN
                'Grey Link'
            ELSE
                'Blue link'
            END
        )

这是可行的,但现在唯一的问题是你已经更改了if语法,这不允许我添加更多的
elseif
@Norman使用
CASE
语句,就像
juergen d
所建议的那样,但现在唯一的问题是你已经更改了if语法,这不允许我添加更多的
elseif
@Norman使用
CASE
语句,如
juergen d