简体   繁体   English

SQL SSRS中的“ IN”表达式

[英]“IN” expression in SQL SSRS

I´ve got this expression here: 我在这里有这样的表达:

WHERE ProductName in ('%Comfort%','%Super%', '%Normal%','%PC%')

BUt it not work. 令它不起作用。 The Table shows me "NaN" Values and Error. 该表显示“ NaN”的值和错误。

Then I´ve tried it with this expression: 然后,我尝试使用以下表达式:

WHERE ProductName like '%Comfort%' AND ProductName like '%Super%' AND ProductName like '%Normal%' AND ProductName like '%PC%'

This was not working, too. 这也不起作用。

If I only use this expression 如果我仅使用此表达式

 WHERE ProductName like '%Comfort%' 

Then it appears me what I want but I miss the other Products in my table. 然后出现我想要的东西,但我错过了桌子上的其他产品。

Well, your second query was almost ok, since column IN(x,y,z) is equals to 好吧,您的第二个查询几乎可以,因为IN(x,y,z)列等于

column = x or column = y or tcolumn = z

And not 并不是

column = x and column = y and tcolumn = z   

The only problem there is you need to replace the 'AND' with an 'OR' like this: 唯一的问题是您需要将“ AND”替换为“ OR”,例如:

WHERE ProductName like '%Comfort%' or ProductName like '%Super%' or ProductName like '%Normal%' or ProductName like '%PC%'

You cannot use wildcards ( % ) in the IN clause. 您不能在IN子句中使用通配符( % )。 The second where is saying ProductName that has "Super" And "Normal" And "PC" in it, so a product name "Normal Super PC" would be returned but not those that do not have all three in the name. 第二个是说其中包含“ Super”和“ Normal”和“ PC”的ProductName ,因此将返回产品名称“ Normal Super PC”,但不会返回名称中没有全部三个名称的产品。

You need to change the AND to OR 您需要将AND更改为OR

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

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