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

后端 未结 1 1122
青春惊慌失措
青春惊慌失措 2021-01-28 22:01

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-se

相关标签:
1条回答
  • 2021-01-28 22:09

    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.

    0 讨论(0)
提交回复
热议问题