SQLTeam.com | Weblogs | Forums

How to use coalesce with the dynamic value


#1

I am trying to modify the below table so that it will have the new column as dado_id based on the following query

declare @results varchar(500)
select @results = coalesce(@results + ',', '') + convert(varchar(12),DADO_ID)
from DADO where PROPERTY_ID =59 (Note: Table 1 Property_ID column)
select @results as results

Table 1:

ID PROPERTY_ID
1 43
2 51
3 52
4 53
5 54
6 55
7 56

Objective to get the below table

ID PROPERTY_ID DADO_ID
1 43 2,4,5
2 51 8,4,6,2
3 52 4,6

Any idea how to do that?


#2

Sure, with a little more information. What does the DADO table look like for sample data to match your example?