UPDATE #Product_Comments
SET #Product_Comments.Comments = (
SELECT COALESCE(STRING_AGG(p.Label, ', '), '') + ' '
from (
select distinct Label, Product_ID
from #TEMPORARYTB
where Product_ID = pc.Product_id
) as p
GROUP BY p.Product_ID
) + pc.Comments from #Product_Comments pc
JOIN Product_Property p ON p.Product_ID = pc.Product_id
I used COALESCE()
when there was just STRING_AGG(p.Label, ', ')
before, and I am still getting NULL
inside comments. If I print Product_Comments before the update, I don't see any NULL
inside comments.
SELECT *, '4' AS debug FROM #Product_Comments
I am printing it like this. So, when I do
SELECT *, '3' AS debug FROM #Product_Comments
I don't see any NULL
, which is weird. It means that the COALESCE
is not working somehow. How can I fix this?
+ pc.Comments from #Product_Comments pc
I have to say, I don't know how sql server handles this, because you don't link it back to the table you're updating. I would've expected an error, actually. Don't you mean+ #Product_Comments.Comments
?