Skip to content
Advertisement

SQL – concatenate strings in variable while loop with +=

I can’t concatenate in this example bellow! When I loop I get my 2 correct results. When I concatenate @MaterialCompositionEn += ‘, ‘ it works fine When I try to concatenate @MaterialCompositionEn += same query to get the 2nd row, I have a null!

Result:

Now when I change to:

I am expecting 20% Cashmere, 80% Wool instead my 3 prints are NULL I tried to CAST but won’t help.

Any idea? Thanks in advance

Advertisement

Answer

I’m guessing there is a much simpler way to do what you want. However, I think the problem is that you need to initialize the string. So at the top of the code block put:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement