构建一个 SSRS 数据集,该数据集根据存储过程的结果查询数据,该存储过程创建一个临时 Table 来存储结果?
Build an SSRS Dataset that Queries for Data Dependent on Results From a Stored Procedure That Creates a Temp Table to Store Results?
我需要构建一个 SSRS 报告来显示来自 SQL Azure table 的查询结果。但是,我的其中一个条件将检查从存储过程(exec team param1、param2)结果集中提取的数据。更复杂的是,存储过程创建了一个临时 table (tempteam
) 来存储结果。如何为我需要的数据编写查询,在我的 where 子句中指定 tempteam
内容?
示例代码
exec team 9596, 2
select * from tempteam
Tempteam 样本结果
consid
9596
23456
24354
20965
....
....
....
您不能只在查询的 WHERE 子句中使用 "TEMP" table 吗?
SELECT *
FROM SOME_TABLE
WHERE ID IN (SELECT consid FROM tempteam)
我不认为 "TEMP" table 实际上是正常的 SQL 临时 table 因为它没有标签 (#tempteam
) 在它前面 - 它看起来像是存储在数据库中的实际 table。
这是您可以使用的一个选项:
EXEC('EXEC team 9596, 2; select * from tempteam')
或参数化:
EXEC('EXEC team ' + @p1 + ',' + @p2 + '; select * from tempteam')
完整重现:
create table test(f1 varchar(256) null)
go
create proc sp_test(@p varchar(256) = 'Hello ')
as
insert test
select @p
return 1
go
declare @p varchar(256) = 'World'
EXEC('EXEC sp_test @p = ''Hello ''; select * from test')
EXEC('EXEC sp_test @p = ' + @p + '; select * from test')
drop proc sp_test
go
drop table test
go
我需要构建一个 SSRS 报告来显示来自 SQL Azure table 的查询结果。但是,我的其中一个条件将检查从存储过程(exec team param1、param2)结果集中提取的数据。更复杂的是,存储过程创建了一个临时 table (tempteam
) 来存储结果。如何为我需要的数据编写查询,在我的 where 子句中指定 tempteam
内容?
示例代码
exec team 9596, 2
select * from tempteam
Tempteam 样本结果
consid
9596
23456
24354
20965
....
....
....
您不能只在查询的 WHERE 子句中使用 "TEMP" table 吗?
SELECT *
FROM SOME_TABLE
WHERE ID IN (SELECT consid FROM tempteam)
我不认为 "TEMP" table 实际上是正常的 SQL 临时 table 因为它没有标签 (#tempteam
) 在它前面 - 它看起来像是存储在数据库中的实际 table。
这是您可以使用的一个选项:
EXEC('EXEC team 9596, 2; select * from tempteam')
或参数化:
EXEC('EXEC team ' + @p1 + ',' + @p2 + '; select * from tempteam')
完整重现:
create table test(f1 varchar(256) null)
go
create proc sp_test(@p varchar(256) = 'Hello ')
as
insert test
select @p
return 1
go
declare @p varchar(256) = 'World'
EXEC('EXEC sp_test @p = ''Hello ''; select * from test')
EXEC('EXEC sp_test @p = ' + @p + '; select * from test')
drop proc sp_test
go
drop table test
go