SSRS不返回具有表值参数的任何数据

时间:2014-11-11 23:29:29

标签: reporting-services

我很难理解为什么在我的表值参数之前或之后添加一个或多个可空参数会返回空记录集。

我在这里成功地遵循了这个例子:http://geekswithblogs.net/GruffCode/archive/2012/06/21/using-table-valued-parameters-with-sql-server-reporting-services.aspx

然后我添加了一个额外的参数来模仿我的环境,除非用@ accountType = 4替换@ accountType = NULL

,否则我无法获得更多记录

以下是数据集中的代码:

exec( ' declare @customerIdList Report.IntegerListTableType ' + @customerIdInserts +
' EXEC rpt_CustomerTransactionSummary
@startDate=''' + @startDate + ''',
@endDate=''' + @endDate + ''',
@customerIds = @customerIdList')

这是sql跟踪(结果:空记录集):

exec sp_executesql N'exec( '' declare @customerIdList Report.IntegerListTableType '' + @customerIdInserts +
'' EXEC rpt_CustomerTransactionSummary
@startDate='''''' + @startDate + '''''',
@endDate='''''' + @endDate + '''''',
@accountType='''''' + @accountType + '''''',
@customerIds = @customerIdList'')',
N'@customerIdInserts nvarchar(40),
@startDate datetime,
@endDate datetime,
@accountType int',
@customerIdInserts=N'INSERT @customerIdList VALUES (304813)',
@startDate='2013-01-01 00:00:00',
@endDate='2014-12-31 00:00:00',
@accountType=NULL

如果我用4替换NULL并在sql management studio中运行查询,我会得到预期的结果:

exec sp_executesql N'exec( '' declare @customerIdList Report.IntegerListTableType '' + @customerIdInserts +
'' EXEC rpt_CustomerTransactionSummary
@startDate='''''' + @startDate + '''''',
@endDate='''''' + @endDate + '''''',
@accountType='''''' + @accountType + '''''',
@customerIds = @customerIdList'')',
N'@customerIdInserts nvarchar(40),
@startDate datetime,
@endDate datetime,
@accountType int',
@customerIdInserts=N'INSERT @customerIdList VALUES (304813)',
@startDate='2013-01-01 00:00:00',
@endDate='2014-12-31 00:00:00',
@accountType=4

有谁能请我指向正确的方向?

由于

瑞克

3 个答案:

答案 0 :(得分:0)

我提供了存储过程后修改了我的答案。我认为accounttype将为0而不是null,因为它是int数据类型。

尝试更改此内容:

  AND (accountType= @accountType OR @accountType = 0)

答案 1 :(得分:0)

这是我的存储过程:

ALTER PROCEDURE dbo.rpt_CustomerTransactionSummary
(
@startDate datetime,
@endDate datetime,
@customerIds Report.IntegerListTableType READONLY,
@accountType int
)
AS
BEGIN
    SET NOCOUNT ON;


  SELECT t.PlayerID, t.InsertedDatetime, t.Amount 
  FROM transactions t
  INNER JOIN @customerIds AS c on t.PlayerID = c.Value
  WHERE InsertedDatetime BETWEEN @startDate AND @endDate 
  AND (@accountType IS NULL OR t.AccountType=@accountType) 


END

答案 2 :(得分:0)

罗伯特你的解决方案有效,但它让我们畏缩加入已经丑陋的黑客。我们通过修复" Text"解决了这个问题。查询类型

exec( ' declare @customerIdList Report.IntegerListTableType ' + @customerIdInserts +
' EXEC rpt_CustomerTransactionSummary
@startDate=''' + @startDate + ''',
@endDate=''' + @endDate + ''',
@accountType=''' + @accountType + ''',
@customerIds = @customerIdList')

DECLARE @vSQL nvarchar(max) = N'
DECLARE @customerIdList Report.IntegerListTableType; 
'+@customerIdInserts+';
EXEC rpt_CustomerTransactionSummary
@startDate=@startDate,
@endDate=@endDate,
@accountType=@accountType,
@customerIds = @customerIdList';
exec sp_executesql 
  @vSQL,
  N'@startDate datetime, @endDate datetime, @accountType int',
  @startDate,
  @endDate,
  @accountType;