[英]SQL / SSRS 2008 - How to combine 2 conditions into a single condition in the WHERE clause?
I have a requirement which appears simple enough but i cannot get this to work. 我有一个看起来很简单的要求,但我无法使它正常工作。 I want to exclude a particular record in my resultset that meets TWO conditions, click the following image to see my current resultset: https://i.stack.imgur.com/z93m3.png .
我想在我的结果集中排除满足两个条件的特定记录,请单击以下图片查看我当前的结果集: https : //i.stack.imgur.com/z93m3.png 。 I want to exclude any lines that have both a selling_price of £84.99 AND a vat_value of £40.83, in my case that would mean i want the last line of my resultset image excluded.
我要排除任何同时具有Selling_price£84.99和vat_value£40.83的行,在我的情况下,这意味着我希望排除结果集图像的最后一行。
I've attempted to use the following as my SQL code: 我尝试使用以下代码作为我的SQL代码:
SELECT created_by, sales_order_number, sales_order_credit_line, qty_credited, sales_order_line, selling_price, vat_value
FROM sales_order_credit
WHERE (selling_price <> 84.99 AND vat_value <> 40.83)
However, as soon as i go to then run the query, the Query Designer reformats my code to read: 但是,一旦我去运行查询,查询设计器就会将我的代码重新格式化为:
SELECT created_by, sales_order_number, sales_order_credit_line, qty_credited, sales_order_line, selling_price, vat_value
FROM sales_order_credit
WHERE (selling_price <> 84.99) AND (vat_value <> 40.83)
Because my code now reads like that, it excludes all lines with a selling price of £84.99 and all lines with a vat_value of £40.83, which is not what i want - i only want to exclude lines that adhere to BOTH of those conditions. 因为我的代码现在是这样写的,所以它排除了所有售价为£84.99的行和所有vat_value为£40.83的行,这不是我想要的-我只想排除同时满足这两个条件的行。
I've ran into this before and never known how this should be done - any help is really appreciated. 我以前曾遇到过这个问题,但从未知道应该怎么做-真的很感谢您的帮助。
Jacob 雅各布
EDIT - Responses to Comments 编辑-评论回应
VKP - thanks for your suggestion, when i add your code it changes to: VKP-感谢您的建议,当我添加您的代码时,它更改为:
SELECT created_by, sales_order_number, sales_order_credit_line, qty_credited, sales_order_line, selling_price, vat_value
FROM sales_order_credit
WHERE (NOT (selling_price = 84.99))
OR
(NOT (vat_value = 40.83))
Again, it takes the two and puts them into completely seperate conditions seperated by OR - which is not what im looking for 再一次,它需要将两者置于完全独立的条件(由OR分隔)中-这不是我正在寻找的东西
Ubiquitous Developers - there is a difference, if you do the reformatted version of the code it will exclude line 4 AND 2, whereas i only want line 4 excluded as it meets both conditions, whereas line 2 only met 1 of the conditions (selling_price) 无处不在的开发人员 -有所不同,如果执行代码的重新格式化版本,它将排除第4行和第2行,而我只希望第4行被排除,因为它同时满足这两个条件,而第2行仅满足其中一个条件(selling_price)
I think the right thing to do in your case is the next: 我认为接下来要针对您的情况做正确的事情:
SELECT created_by, sales_order_number, sales_order_credit_line, qty_credited, sales_order_line, selling_price, vat_value
FROM sales_order_credit
WHERE NOT (selling_price = 84.99 AND vat_value = 40.83)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.