See title. Basically, the data in this report is set up such that each value in Field A has multiple corresponding values in Field B, and I need to display Field B as a comma-separated list. According to the internets, this is totally easy via a combination of Join() and LookupSet() in 2008... but I'm on 2005. Anyone know how I can do this?
A:
Here is my structure:
CREATE TABLE [dbo].[Regional](
[State] [char](20) NULL,
[Region] [char](10) NULL,
[County] [char](20) NULL
)
Here is my query:
SELECT state,
region,
(SELECT Rtrim(county) + ','
FROM regional b
WHERE a.state = b.state
AND a.region = b.region
FOR XML PATH('')) counties,
Count(*) countycount
FROM regional a
GROUP BY state,
region
Here is the output:
state region counties countycount
AL South Mobile,Baldwin, 2
MS South Jackson,Harrison,Stone, 3
You will notice a trailing ',' that you will need to trim. That should be simple if your displaying this in SSRS.
Kenneth
2010-06-11 18:07:06
Hey, thanks! That definitely looks like something I can work with.
extarbags
2010-06-11 19:15:25