简体   繁体   中英

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:

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 :

param_clientID ,param_birthDay

I would like to use these parameters in a where clausule ONLY if they are filled.

where clientID = param_clientID and birthday = param_birthDay

It should be possible that the clientID is filled, and the birthday parameter not. 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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