1

我可以连接结果值,然后将最终值作为输出发送。

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

但最后 totalshipmentexpenseamount 没有任何价值。

4

1 回答 1

1

不知道您提供的代码之前是什么,但您可以尝试以下操作:

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

这是因为第一次totalshipmentexpenseamount设置为null,当你null与其他东西连接时它会出来null。如果是,coalesce则将返回空totalshipmentexpenseamountnull

编辑:

改成这个

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

由于您使用逗号连接,这将在第一次传递中设置值,indshipmentexpenseamount否则将totalshipmentexpenseamount使用逗号连接indshipmentexpenseamount

于 2013-09-18T08:07:18.747 回答