Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在函数中使用case时的MySql concat_Mysql_Sql - Fatal编程技术网

在函数中使用case时的MySql concat

在函数中使用case时的MySql concat,mysql,sql,Mysql,Sql,如何将concatafixed string转换为动态生成的文本?对于这个例子,我一直保持简单,但实际情况是很多。因此,我不想让它到处都是,而是希望concatit并将其发送到输出 BEGIN DECLARE aId INT; DECLARE aType INT; DECLARE aParent INT; DECLARE aUserName VARCHAR(32); DECLARE aUserId INT; DECLARE aCountry VAR

如何将
concat
a
fixed string
转换为动态生成的
文本?对于这个例子,我一直保持简单,但实际情况是很多。因此,我不想让它到处都是,而是希望
concat
it并将其发送到输出

BEGIN
    DECLARE aId INT;
    DECLARE aType INT;
    DECLARE aParent INT;
    DECLARE aUserName VARCHAR(32);
    DECLARE aUserId INT;
    DECLARE aCountry VARCHAR(2);
    DECLARE aOutput VARCHAR(1500); 

    SELECT id, type, parent INTO aId, aType, aParent FROM products  WHERE id = mElmId;

    SET aOutput = CASE atype
        WHEN 1 THEN 'Something'
        WHEN 2 THEN 'Something'
        WHEN 3 THEN  'Something'
        WHEN 10 THEN  
            CASE mStatus
                WHEN '14' THEN 'Place Order Link'
                WHEN '01' THEN 'Cancel Order Link'
                WHEN '11' THEN 'Order Cancelled - Place order link'
                WHEN '00' THEN 'Order - Under Process'#No link here
                WHEN '10' THEN 'Cancel - Under Process' #No link here
                ELSE 'Detect Status Error'
            END
            //I need to concat 'Home ~ More' to the above text, but don't want to add it next to the text above.
            //So it ends up like 'Place Order Link ~ Home ~More'
        ELSE 'Error generating link'
    END;

  RETURN (aOutput);
END
这是你想要的吗

SET aOutput = CASE atype
    WHEN 1 THEN 'Something'
    WHEN 2 THEN 'Something'
    WHEN 3 THEN  'Something'
    WHEN 10 THEN  
        concat(CASE mStatus
                  WHEN '14' THEN 'Place Order Link'
                  WHEN '01' THEN 'Cancel Order Link'
                  WHEN '11' THEN 'Order Cancelled - Place order link'
                  WHEN '00' THEN 'Order - Under Process'#No link here
                  WHEN '10' THEN 'Cancel - Under Process' #No link here
                  ELSE 'Detect Status Error'
              END, ' Home ~ More')
        //I need to concat 'Home ~ More' to the above text, but don't want to add it next to the text above.
        //So it ends up like 'Place Order Link ~ Home ~More'
    ELSE 'Error generating link'

在您的代码段中,未定义
mStatus
。我假设在原始代码中,这已得到处理。

mStatus在调用函数时被传递。这正是我希望做的。非常感谢你的帮助。