当参数中没有值时,如何传递ssrs中表中的所有值?

Pra*_*mar 6 sql sql-server sql-server-2008-r2 reporting-services

我正在传递两个参数,即@AccountId@key.我想显示数据库中存在的所有值@AccountId以及@key参数中没有值的时候ie @AccountId@key.我想为同一个数据集执行此操作.这是可能的还是我创建了不同的数据集?

我使用的查询是:

CREATE PROCEDURE [dbo].[GetDenyList]
@AccountId nvarchar(100),
@key nvarchar(400)
AS
select New_AccountId AS 'AccountId/Key', New_Description AS 'Reason',CreatedOn AS 'Date'
  from abc.dbo.New_keydenylist 
 where New_AccountId is not null
   AND @AccountId = New_AccountId
 union all
select new_key AS 'AccountId/Key', New_Description AS 'Reason',CreatedOn AS 'Date' 
  from abc.dbo.New_keydenylist 
 where New_key is not null
   and @Key=New_key
Run Code Online (Sandbox Code Playgroud)

Mah*_*mal 0

如果我很好地理解你的问题,那么你必须使用任何始终评估为 true 的谓词,无论传递给子句的参数值如何WHERE。例如WHERE 1 = 1

 WHERE 1 = 1
 AND (@AccountId IS NOT NULL OR AccountId = @AccountId)
Run Code Online (Sandbox Code Playgroud)

与参数相同@key

 WHERE 1 = 1
 AND (@key IS NOT NULL OR New_key = @key)
Run Code Online (Sandbox Code Playgroud)

如果两个参数@key@AccountId都是两者NULL或其中之一,则该WHERE子句仍然有效并返回所有未呈现的行。