简体   繁体   中英

Dynamically Change Where Clause Condition Based on Parameter Selection (SSRS)

I have built an SSRS report, but am unable to get over one hurdle. It may be simple, I am just unsure of how to solve this.

I have a parameter drop down that allows the user to select one of two options, if they select one option the a portion of the where clause should change, and if the other is chosen it would change again. I will post it below :

If master is chosen :

WHERE myId=1 AND myJournal IS NULL

If Idol is chosen :

WHERE myId=1

So basically just adding a condition and taking a condition based on parameter selection....

This seems very rudimentary, I just can't seem to figure it out.

Thanks for any input

How about

WHERE myId=1 AND (myJournal IS NULL OR @Parameter = 'Idol')

assuming your parameter value get set to Idol of course

The way this works is:

If @Parameter = 'Idol', then the OR clause in the brackets will always be true , regardless of the myJournal value. This reduces the entire WHERE clause to WHERE myId=1 AND true , which is the same as WHERE myId=1 .

However if @Parameter = 'master', then the OR clause in the brackets will only be true if myJournal IS NULL as @Parameter = 'Idol' is always false . This means the OR clause can be thought of as equivalent to simply myJournal IS NULL .

This reduces the entire WHERE clause to WHERE myId=1 AND myJournal IS NULL , which is what you are after.

You don't provide any information about the way you want to perform the query.

Do you want to do it with an ajax call?

In this case you should have a selectcombo which will set the needed query string and pass this with an ajax request to the php file that will query the database.

If you want some help we need to have some more information about what you are trying to achieve.

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