[英]MySql concat when using case inside a function
How can I concat
a fixed string
to text that is dynamically generated
in the case below? 我怎样才能
concat
一个fixed string
文本是dynamically generated
在下面的情况? I've kept it simple for this example, but the real thing is a lot. 在此示例中,我将其简化,但实际情况很多。 So instead of having it all over the place, I'd like to
concat
it and send it off to the output. 因此,我希望将其
concat
并发送到输出,而不是到处都放。
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
Is this what you want? 这是你想要的吗?
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'
In your code snippet, mStatus
is not defined. 在您的代码段中,
mStatus
。 I assume that in the original code, this is taken care of. 我假设在原始代码中已经解决了这一问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.