简体   繁体   English

拿到 SQL Server Reporting Services中存储过程返回的行数

[英]Get no. of rows returned by stored procedure in SQL Server Reporting Services

I have created a report using SQL Server Reporting Services that makes use of a stored procedure. 我已经使用SQL Server Reporting Services创建了一个使用存储过程的报告。 I added the stored procedure as a Dataset for the report and its making use of parameters to do some filtering etc. 我将存储过程添加为报表的数据集,并利用参数进行过滤等。

This all works perfectly, but I want to display the no. 所有这些都完美运行,但是我要显示否。 of rows that were returned by the stored procedure at the bottom of the report. 报告底部的存储过程返回的行数。 In attempt to do this I added an output parameter to my stored procedure and i have this statement after the SELECT statement: 为了做到这一点,我在存储过程中添加了一个输出参数,并在SELECT语句后添加了以下语句:

SET @Count = @@ROWCOUNT

This parameter appears in my parameter list in Visual Studio and I added it to my report, but its value is always 0. 此参数显示在Visual Studio的参数列表中,并将其添加到报表中,但其值始终为0。

火星报告参数

火星报告计数输出

What I'm wondering is how am I supposed to catch the output parameter in my report, or is there some other way to get this count in my report? 我想知道我应该如何在报告中捕获输出参数,或者是否有其他方法可以在报告中获取此计数?

It's not possible to directly catch output parameters of Stored Procedures using Reporting Services. 使用Reporting Services无法直接捕获存储过程的输出参数。

The easiest way to get the number of records in the returned dataset, is simply to use an expression in the textbox where you want to show the count: 获取返回数据集中记录数的最简单方法是,在要显示计数的文本框中使用表达式:

=CountRows("stp_CityHealthResearchRequests")

If you want to filter your count, use the Sum-function together with the Iif-function. 如果要过滤计数,请同时使用Sum函数和Iif函数。 For example, if you only want to count the number of records where the Concluded-column has the value "Yes": 例如,如果您只想计算“结论”列中值为“是”的记录数:

=Sum(Iif(Fields!Concluded.Value = "Yes",1,0),"stp_CityHealthResearchRequests")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM