select t.EntityID, t.AttributeID, stuff(x.Options, 1 , 1 , '') Options from ( select EntityID, AttributeID from @YourTable group by EntityID, AttributeID ) t cross apply ( select ',' + OptionText from @YourTable where EntityID = t.EntityID and AttributeID = t.AttributeID for xml path('') ) x(Options);If this does not help much then you can try using the dynamic pivot first and then the normal concat to derive your delimited lists (one for each combination). This will make the query much more complex, but considerably cheaper and probably faster. Please let me know if you want it and I can post a sample.
No one has followed this question yet.
Problem with CASE Statement in T-SQL
Matching corresponding records from two or more tables
Performance hit while Comparing Rows in absence of key
Is it possible to simulate older versions of SQL Server without having them installed?
Logic for Stored Proc for selecting multiple comma separated values in parameter?