简体   繁体   English

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

[英]Dynamic sql query in SSRS (Sql Server Report Server 2012)

I have created in vs2010 a report with the name " clients ", which shows a list of clients with the following attributes: 我在vs2010中创建了一个名为“ clients ”的报告,其中显示了具有以下属性的客户端列表:

clientID,firstname,lastname,adres,country,birthday

I have created this report with a datasource and a dataset. 我用数据源和数据集创建了这个报告。 In this dataset I have created a query like this: 在这个数据集中,我创建了一个这样的查询:

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

This is working! 这很有效!

I would like to add 2 optonal parameters : 我想添加2 optonal parameters

param_clientID ,param_birthDay

I would like to use these parameters in a where clausule ONLY if they are filled. 如果填充,我想在where clausule中使用这些参数。

where clientID = param_clientID and birthday = param_birthDay

It should be possible that the clientID is filled, and the birthday parameter not. 应该可以填充clientID,而不是生日参数。 Otherwise also. 否则也。

How can I do this? 我怎样才能做到这一点?

Adding (optional) parameters to you report is quite easy. 向您报告添加(可选)参数非常简单。

First of all make your parameters nullable. 首先使您的参数可以为空。

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

For more detailed description: 有关更详细的说明:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM