Coalesce will return the first non-null value among its arguments
documentation says. I can also use it like below:
DECLARE @ColumnValue VARCHAR(MAX);
SELECT @ColumnValue = COALESCE(@ColumnValue+',','') + ColumnValue
FROM dbo.TableA
SELECT @ColumnValue
According to my understanding, there should be a ,
at the very front of the output list since at the very beginning there will at least be a comma passed as an argument. Also, if I put some value in the second argument. It appears at the very front instead of the ,
as I expected.
If someone can please explain the code to me. I will be very grateful.