Is there a better way to do this Concatenation in SQL Server 2008? -
i've got following sql statement subquery concatenation. if notice, uses for xml ..
.. .. gives me shivers bit :: feel it's code-smell.
is there better way sql server 2008 ?
select a.cityid locationid, a.city, stuff( (select ', ' + x.county [dbo].[countiesview] x inner join [dbo].[citycounties] y on x.countyid = y.countyid y.cityid = a.cityid xml path ('')) , 1, 2, '') [dbo].[citiesview] a.statecode = 'ny'
what code doing listing cities (and counties) state of new york. because city can exist in 1 or more counties, wish concatenate county names ... otherwise i'll 1 city row per county (which don't want).
can refactored, better?
i tried use coalesce had no luck.
"better" in eye of beholder. haven't seen better way in sql server 2005+, haven't been looking hard.
the best way program own aggregate function. think i'd rather maintain query.
Comments
Post a Comment