【问题标题】:Fit multiple results returned from one dataset in single textbox将一个数据集返回的多个结果拟合到单个文本框中
【发布时间】:2019-05-22 03:05:38
【问题描述】:

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

   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-services ssrs-2017


    【解决方案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。

    【讨论】:

    • 将尝试此操作并标记为答案。非常感谢。
    【解决方案2】:

    如果您想将所有内容都放在一个文本框中,则需要将所有内容都写在一个表达式中。像这样:

    假设以下表达式返回您的 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)
    

    【讨论】:

    • 是这样,我需要将所有这些表达式放在一个文本框中吗?此外,您还提供了硬编码值(所提供的只是一个示例)。这些值是动态的。请问还有什么线索吗?
    • 然后只需将名称替换为适当的字段="Here is the " & Fields!Name.Value " & " count: " & Sum(Fields!Count.Value)etc...
    猜你喜欢
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    相关资源
    最近更新 更多