Displaying a field as a comma separated list in Reporting Services 2005?

半腔热情 提交于 2019-12-02 10:55:51

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!