>Hi
>
>I've got a table individual and a table attribute in SQL2008
>
>A line in individual can have several entries in attribute linked on indvividual_ref.
>
>I want to produce a result with indvidual_ref,attribute_string
>
>where attribute string is a delimited string of all the attribute codes for that individual
>
>Any tips on how I'd get that.
>
>Thanks
>
>Nick
select I.*, stuff((select ', ' + attribute from dbo.Attribute A where A.Individual_ID = I.Individual_ID
order by Attribute FOR XML PATH(''), type).value('.', 'varchar(max)'),1,2,'') as Attribute_String
from dbo.Individual I ORDER BY I.LastName
Take a look at this blog post
Making a list and checking it twice
If it's not broken, fix it until it is.
My Blog