不知道您提供的代码之前是什么,但您可以尝试以下操作:
WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
SET totalshipmentexpenseamount = CONCAT(COALESCE(totalshipmentexpenseamount, ''),',',indshipmentexpenseamount);
END;
END WHILE;
这是因为第一次totalshipmentexpenseamount
设置为null
,当你null
与其他东西连接时它会出来null
。如果是,coalesce
则将返回空totalshipmentexpenseamount
null
编辑:
改成这个
WHILE(LENGTH(totalexpenseamount )>0) DO
BEGIN
SET totalshipmentexpenseamount = COALESCE(CONCAT(totalshipmentexpenseamount,',',indshipmentexpenseamount), indshipmentexpenseamount);
END;
WHILE;
由于您使用逗号连接,这将在第一次传递中设置值,indshipmentexpenseamount
否则将totalshipmentexpenseamount
使用逗号连接indshipmentexpenseamount