简体   繁体   English

在MySQL中连接结果值

[英]Concat the resulting value in mysql

Can i concat result value and then send the final value as output. 我可以合并结果值,然后将最终值作为输出发送。

WHILE(LENGTH(totalexpenseamount )>0) DO
        BEGIN
              SET totalshipmentexpenseamount = CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount);
END;
    END WHILE;

but at end totalshipmentexpenseamount does not have any value in it. 但最终totalshipmentexpenseamount中没有任何值。

don't know what is before the code that you presented, but you can try the following: 不知道所显示的代码之前是什么,但是您可以尝试以下操作:

WHILE(LENGTH(totalexpenseamount )>0) DO
        BEGIN
              SET totalshipmentexpenseamount = CONCAT(COALESCE(totalshipmentexpenseamount, ''),',',indshipmentexpenseamount);
END;
    END WHILE;

this is because totalshipmentexpenseamount is set to null in the first time and when you concat null with other thing it comes out null . 这是因为第一次将totalshipmentexpenseamount设置为null ,并且当您将null与其他内容结合起来时,结果为null The coalesce will return empty if totalshipmentexpenseamount is null 如果totalshipmentexpenseamountnullcoalesce将返回空

EDIT: 编辑:

Change to this 改成这个

WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
    SET totalshipmentexpenseamount = COALESCE(CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount), indshipmentexpenseamount);
END;
WHILE;

Since you have concatenation with a comma, this will set in the first pass the value of indshipmentexpenseamount otherwise will concat the totalshipmentexpenseamount with a comma and the indshipmentexpenseamount 由于您使用逗号串联,因此将在第一遍中设置indshipmentexpenseamount的值,否则将用逗号将indshipmentexpenseamounttotalshipmentexpenseamountindshipmentexpenseamount

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM