简体   繁体   English

WHERE子句中的SSRS参数值

[英]SSRS Parameter values in WHERE clause

(edited to clean up) (编辑以进行清理)

I have an SSRS report with a multi-value parameter. 我有一个带有多值参数的SSRS报告。 What I need is for each value of the parameter to correspond to a condition in the "where" clause. 我需要的是参数的每个值都对应于“ where”子句中的条件。

So my query is like this: 所以我的查询是这样的:

select stuff,...

WHERE

column A != column B OR
column C != column D OR...

just like that all the way down. 就这样一直下去。 It's to give results only if there's a difference between different pairs of columns. 仅当不同的列对之间存在差异时才给出结果。

So hope I'm describing it well. 所以希望我能很好地描述它。 So, for example, if the above is my where clause, I want the parameter to have values like this: 因此,例如,如果以上是我的where子句,则我希望参数具有这样的值:

"Difference between A & B" "Difference between C & D" “ A与B之间的差异”“ C与D之间的差异”

and be able to select multiple...so only the ones the user selects are incorporated. 并可以选择多个...因此仅合并了用户选择的内容。

EDIT - PARTIAL SOLUTION ********************************************** 编辑-部分解决方案**************************************************

Ok I have the logic, thanks to the right direction from Hannover Fist, I came up with this: 好的,我有逻辑,由于汉诺威拳王的正确指导,我想到了这一点:

WHERE
col 1 <> CASE WHEN CHARINDEX("Where1",@Parameter) = 0 THEN col 1 ELSE col 2 END OR  
col 3 <> CASE WHEN CHARINDEX("Where2",@Parameter) = 0 THEN col 3 ELSE col 4 END 

...etc..... ...等等.....

This way, if the parameter is not selected, that part of the where clause looks for results where that column is not equal to itself--so none, of course... 这样,如果未选择参数,则where子句的该部分将在该列与其自身不相等的地方寻找结果-因此,当然没有...

However, one problem remains. 但是,仍然存在一个问题。 This works in SSRS if I only choose 1 of the parameter values, but if I choose more than one, I get an error "charindex function requires 2 to 3 arguments." 如果我仅选择一个参数值,则在SSRS中有效,但是如果选择多个参数值,则会收到错误消息“ charindex函数需要2到3个参数”。 >-( >-(

I deployed it and it spat something slightly different: 我部署了它,它吐出一些稍微不同的东西:

Argument data type nvarchar is invalid for argument 3 of charindex function 参数数据类型nvarchar对于charindex函数的参数3无效

Something about SSRS's handling of this is flapdoodle, but I'm not sure what. 关于SSRS处理此问题的方法是flappoodle,但我不确定是什么。

I'm a little fuzzy as to how you're trying to do this. 关于您如何尝试执行此操作,我有点模糊。

How about having your WHERE clause in your SQL and use your parameter to determine whether that part of the WHERE is used? 如何在SQL中使用WHERE子句并使用参数确定是否使用了WHERE的那一部分? This may not be exactly what you need but should give you an idea of what I mean. 这可能不完全是您所需要的,但应该使您了解我的意思。

WHERE (ColA <> ColB or CHARINDEX("Where1", @Parameter) = 0)

Your Parameter would have Where1 as one of the selections (for the Value - the Label could be more descriptive). 您的参数将使用Where1作为选择之一(对于 - 标签可能更具描述性)。 If it's chosen, the CHARINDEX result would not be 0 and the ColA <> ColB condition would need to be true to show that record. 如果选择它,则CHARINDEX结果将0 ,并且ColA <> ColB条件必须为true才能显示该记录。

Repeat for each parameter/WHERE combo you need. 对所需的每个参数/ WHERE组合重复上述步骤。

Got it. 得到它了。
As edited above, this code works (helpful nudge in this direction from Hannover Fist): 如上所编辑,此代码有效(从Hannover Fist朝此方向微调):

WHERE  
col 1 <> CASE WHEN CHARINDEX("Where1",@Parameter) = 0 THEN col 1 ELSE col 2 END OR
col 3 <> CASE WHEN CHARINDEX("Where2",@Paremeter) = 0 THEN col 3 ELSE col 4 END

etc... 等等...

And the parameter issue is new to my experience, but put simply (which is not done often--hence my difficulty :-P), SSRS includes the commas between parameter values (which makes sense since we can use an IN statement such as WHERE column IN (@Parameter) 参数问题对于我的经验来说是新的,但简单地说(这并不经常执行-因此我很困难:-P),SSRS包含参数值之间的逗号(这很有意义,因为我们可以使用IN语句,例如WHERE列IN(@Parameter)

So that is why it complained when I selected more than one. 这就是为什么当我选择一个以上时它抱怨的原因。 Incorporating the excellent selected answer here: 在此处合并出色的选择答案:

Passing multiple values for a single parameter in Reporting Services 在Reporting Services中为单个参数传递多个值

Solved the rest of the problem :) 解决了其余问题:)

将多值参数传递给数据集时,将多值参数与表达式连接

= JOIN(Parameters!multivalue parameter.Value,",")

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

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