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

本小妞迷上赌 提交于 2019-12-02 18:05:02

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3024456/displaying-a-field-as-a-comma-separated-list-in-reporting-services-2005

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