我可以在 SQL Server 报表生成器中使用 @table 变量吗?
使用 SQL Server 2008 报告服务:
我正在尝试编写一个显示一些相关数据的报告,因此我想使用像这样的 @table 变量
DECLARE @Results TABLE (Number int
,Name nvarchar(250)
,Total1 money
,Total2 money
)
insert into @Results(Number, Name, Total1)
select number, name, sum(total)
from table1
group by number, name
update @Results
set total2 = total
from
(select number, sum(total) from table2) s
where s.number = number
select from @results
但是,报告生成器不断要求输入变量 @Results 的值。这到底有可能吗?
编辑:按照 KM 的建议,我使用了存储过程来解决眼前的问题,但最初的问题仍然存在:我可以在报表生成器中使用 @table 变量吗?
Using SQL Server 2008 Reporting services:
I'm trying to write a report that displays some correlated data so I thought to use a @table variable like so
DECLARE @Results TABLE (Number int
,Name nvarchar(250)
,Total1 money
,Total2 money
)
insert into @Results(Number, Name, Total1)
select number, name, sum(total)
from table1
group by number, name
update @Results
set total2 = total
from
(select number, sum(total) from table2) s
where s.number = number
select from @results
However, Report Builder keeps asking to enter a value for the variable @Results. It this at all possible?
EDIT: As suggested by KM I've used a stored procedure to solve my immediate problem, but the original question still stands: can I use @table variables in Report Builder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不会。ReportBuilder
会
No.
ReportBuilder will
将所有这些内容放入存储过程中,并让报表生成器调用该过程。如果您有很多行要处理,那么使用 #temp 表可能会更好(性能方面),您在 Number 上创建聚集主键(或者是 Number+Name,不确定您的示例代码)。
编辑
您可以尝试在一个 SELECT 中完成所有操作并将其发送到报告生成器,这应该是最快的(没有临时表):
Put all of that in a stored procedure and have report builder call that procedure. If you have many rows to process you might be better off (performance wise) with a #temp table where you create a clustered primary key on Number (or would it be Number+Name, not sure of your example code).
EDIT
you could try to do everything in one SELECT and send that to report builder, this should be the fastest (no temp tables):
我也见过这个问题。 SQLRS 似乎有点区分大小写。如果您确保表变量在各处都使用相同的字母大小写进行声明和引用,您将清除参数提示。
I've seen this problem as well. It seems SQLRS is a bit case-sensitive. If you ensure that your table variable is declared and referenced everywhere with the same letter case, you will clear up the prompt for parameter.
您可以在 SSRS 数据集查询中使用表变量,就像在我的代码中一样,我添加了所需的“空”记录以将组页脚保持在固定位置(示例使用 pubs 数据库):
You can use Table Variables in SSRS dataset query like in my code where I am adding needed "empty" records for keep group footer in fixed postion (sample use pubs database):
为什么不能将两个结果集联合起来?
Why can't you just UNION the two resultsets?
使用表值函数而不是存储过程怎么样?
How about using a table valued function rather than a stored proc?
可以,只用“@@”声明您的表。例子:
It's possible, only declare your table with '@@'. Example: