首页 > 解决方案 > 将一个数据集返回的多个结果拟合到单个文本框中

问题描述

我有一个数据集,它返回如下结果:

   SELECT 
    [Name] 
     ,[Count]
   FROM [dbo].[TestTable1]

   ID           Name                    Count
   ------------------------------------------
    1           International school    100
    2           World school            200
    3           Universe school         400

我有一个文本框,我想在其中显示计数。 在此处输入图像描述

            Here is the international school count: «Expr»
            Here is the world school count:    «Expr»
            Here is the Universe school count: «Expr»

我正在寻找一个结果应该返回如下的表达式:

            Here is the international school count: 100
            Here is the world school count:    200
            Here is the Universe school count: 400

这是我的示例表达式:

            =IIF(First(Fields!Name.Value, "CountinOneBox")="International school",(Fields!Count.Value, "CountinOneBox"),"")

注意:sum(Fields!Count.Value, "CountinOneBox") 提供 700

希望我已经正确解释了这一点。我怎样才能得到这个结果?谢谢。

标签: reporting-servicesssrs-2017

解决方案


我会在 SQL 中执行此操作。我已经在此处复制了您的示例数据,然后将结果字段放入了一个简单的报告中

DECLARE @t table(ID int, [Name] varchar(100), [Count] int)

INSERT INTO @t VALUES
    (1, 'International school', 100),
    (2, 'World school', 200),
    (3, 'Universe school', 400)

DECLARE @s nvarchar(max) = ''
DECLARe @crlf char(2) = char(13) + char(10)

SELECT @s = 
        @s + 'Here is the ' 
           + [Name] 
           + ' count: ' 
           + CAST([COUNT] as varchar(10)) 
           + @crlf
    FROM @t

SELECT @s as Result

结果看起来像这样。(我在文本框上设置了一个边框,所以你可以看到它没有换行,它使用了我们添加的 CR/LF。

在此处输入图像描述


推荐阅读