SSRS中的动态sql查询(sql Server Report Server 2012)



我在vs2010中创建了一个名为" clients "的报告,其中显示了具有以下属性的客户端列表:

clientID,firstname,lastname,adres,country,birthday

我用一个数据源和一个数据集创建了这个报告。在这个数据集中,我创建了一个这样的查询:

select firstname, lastname, adres, country, birthday
from clients

这是工作!

我想添加2个optonal parameters:

param_clientID ,param_birthDay

我想只在where子句中使用这些参数,如果它们是填充的。

where clientID = param_clientID and birthday = param_birthDay

应该有可能填充了clientID,而没有填充生日参数。否则也。

我该怎么做?

在报表中添加(可选的)参数非常容易。

首先让你的参数可为空。

select firstname, lastname, adres, country, birthday 
from clients
where (clientID = @clientID or @clientID is null) 
and (birthday = @birthDay or @birthDay is null)

查看更详细的说明:

  • 参数:http://msdn.microsoft.com/en-us/library/aa337432 (v = sql.105) . aspx
  • 可选参数http://bloggingabout.net/blogs/egiardina/archive/2007/06/26/sql-server-reporting-services-optional-parameters.aspx

最新更新