在单个文本框中拟合从一个数据集返回的多个结果

时间:2019-05-22 03:05:39

标签: reporting-services ssrs-2017

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

[]

我有一个文本框,我想在其中显示计数。 enter image description here

   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

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

希望我已经正确解释了这一点。如何获得此结果?谢谢。

2 个答案:

答案 0 :(得分:1)

我会在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。

enter image description here

答案 1 :(得分:0)

如果要在一个文本框中包含所有内容,则需要在一个表达式中编写所有内容。像这样:

假设下面的表达式返回您的100、200、400。

=Sum(Fields!Result1.Value)  ' 100
=Sum(Fields!Result2.Value)  ' 200
=Sum(Fields!Result3.Value)  ' 400


="Here is the international school count: " & Sum(Fields!Result1.Value) & VbNewLine &
 "Here is the world school count: " & Sum(Fields!Result2.Value) & VbNeLine &
 "Here is the Universe school count: " & Sum(Fields!Result3.Value)