I have the attached and SP code snippet which, when fed a VCHRNMBR variable, will return up to 4 rows. I need to design a WHILE Loop to combine the DistRef field from all the returned records and concatenate them in one field, delimited by a comma. I am new to working with WHILE loops, how would I go about this?
SELECT coalesce(pm1.DistRef+',','')+ pm1.DistRef as 'TEXT'
from PM20000 pm2
join PM10100 pm1 ON pm2.VCHRNMBR=pm1.VCHRNMBR
where @VCHRNMBR = pm2.VCHRNMBR