简体   繁体   English

基于参数选择(SSRS)动态更改条款条件

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

I have built an SSRS report, but am unable to get over one hurdle. 我已经建立了一个SSRS报告,但无法克服一个障碍。 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. 我有一个参数下拉列表,允许用户选择两个选项之一,如果他们选择一个选项,则where子句的一部分应更改,如果选择另一个,则它将再次更改。 I will post it below : 我将在下面发布:

If master is chosen : 如果选择了master:

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. 如果@Parameter ='Idol',则无论myJournal值如何,括号中的OR子句始终为true This reduces the entire WHERE clause to WHERE myId=1 AND true , which is the same as WHERE myId=1 . WHERE myId=1 AND true整个WHERE子句减少为WHERE myId=1 AND true ,与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 . 但是,如果@Parameter ='master',则括号中的OR子句只有在myJournal IS NULL时才为true ,因为@Parameter = 'Idol'始终为false This means the OR clause can be thought of as equivalent to simply myJournal IS NULL . 这意味着可以将OR子句视为等同于myJournal IS NULL

This reduces the entire WHERE clause to WHERE myId=1 AND myJournal IS NULL , which is what you are after. WHERE myId=1 AND myJournal IS NULL整个WHERE子句减少为WHERE myId=1 AND myJournal IS NULL ,这是您要WHERE myId=1 AND myJournal IS NULL

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? 你想用一个ajax调用吗?

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. 在这种情况下,您应该有一个selectcombo,它将设置所需的查询字符串,并将其与ajax请求一起传递给将查询数据库的php文件。

If you want some help we need to have some more information about what you are trying to achieve. 如果您需要帮助,我们需要更多有关您要实现的目标的信息。

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

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