Get an extra comma ',' while using concat

mysql

Solution

By using an `IF`:

UPDATE recipes_new 
SET co_auths = IF(co_auths IS NULL, c1id, CONCAT(co_auths, ',', c1id))
WHERE id = name_in; 

If the value of `co_auths` is an empty string instead of `NULL`:

UPDATE recipes_new 
SET co_auths = IF(LENGTH(co_auths), CONCAT(co_auths, ',', c1id), c1id)
WHERE id = name_in; 

Problem

I have wrote a stored proc in `sqlyog`. It is quite long and performing all the desired functionality except for the concat statement so I will only list that particular query. ``` UPDATE recipes_new SET co_auths = CONCAT(co_auths,',',c1id) WHERE id = name_in; ``` I basically want a separation in the two fields and this statement is placed in a cursor so it is iterative. `co_auths` is null at the moment so I get the result as ,1,2,3 where as I want it to be 1,2,3. Any guesses what can the most appropriate solution be?

Original source

Related problems