将一个数据集返回的多个结果放入单个文本框中

Fit multiple results returned from one dataset in single textbox

我有一个数据集,returns 结果如下:

   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»

我正在寻找一个表达式,其中的结果应该 return 如下所示:

            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

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

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

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

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