Hacker
Hacker

Reputation: 7906

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.

Upvotes: 1

Views: 50

Answers (1)

saamorim
saamorim

Reputation: 3905

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 nullin the first time and when you concat null with other thing it comes out null. The coalesce will return empty if totalshipmentexpenseamount is null

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

Upvotes: 1

Related Questions