Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SSRS-动态数据集_Sql Server_Stored Procedures_Reporting Services - Fatal编程技术网

Sql server SSRS-动态数据集

Sql server SSRS-动态数据集,sql-server,stored-procedures,reporting-services,Sql Server,Stored Procedures,Reporting Services,我有一个使用存储过程的报告,根据参数值的选择,该存储过程可以有三种不同的输出 参数报告类型具有以下选项:日/月/年 如果用户选择Day,则在使用表A和返回列1、2、3的过程中会有一条If语句 如果用户选择Month,则会有一个If语句使用表B并返回第4、5、6列 今年的情况也一样 因此存储过程可能返回: Select column 1, 2, 3 from Table 1 Select column 4, 5, 6 from Table 2 Select column 7, 8

我有一个使用存储过程的报告,根据参数值的选择,该存储过程可以有三种不同的输出

参数报告类型具有以下选项:日/月/年

如果用户选择Day,则在使用表A和返回列1、2、3的过程中会有一条If语句

如果用户选择Month,则会有一个If语句使用表B并返回第4、5、6列

今年的情况也一样

因此存储过程可能返回:

   Select column 1, 2, 3 from Table 1
   Select column 4, 5, 6 from Table 2
   Select column 7, 8, 9 from Table 3
如您所见,我使用此存储过程在报表中创建的数据集无法刷新字段,它会将字段拉入报表中供我使用


如何在报表中使用一个具有不同返回值的存储过程,以便设置字段以显示数据?

我认为最好的方法是让每个案例返回相同的列名和类型集。如果一种情况返回的列数少于另一种情况,则只需使用空值填充额外的列。

您可以通过SP决定参数并进行计算的方式来执行此操作

CREATE PROCEDURE dbo.uspGetData @paramValue nvarchar(30)
AS

  Select [column 1] as col1, [column 2] as col2, [column 3] as col3 from [Table 1] where @paramValue=N'Day'
  UNION 
  Select [column 4] as col1, [column 5] as col2, [column 6] as col3 from [Table 2] where @paramValue=N'Month' 
  UNION
  Select [column 7] as col1, [column 8] as col2, [column 9] as col3 from [Table 3] where @paramValue=N'Year'
GO

谢谢你的帮助。这是有道理的,感谢你的帮助