I am trying to produce a single table query result with error payment data filtered out by the conditions below. I am unable to get the query to filter out all of the sets of conditions, only the first 3. I have tried different ordering as well as making the last two condition sets a sub-query.
我正在尝试生成单个表查询结果,其中错误付款数据按以下条件过滤掉。我无法获得查询来过滤掉所有条件集,只有前三个。我尝试了不同的排序以及使最后两个条件集成为子查询。
How can I filter out all the below conditions?
如何过滤掉以下所有条件?
Again, 1,2 and 3 seem to have the desired result.Conditions 4 and 5 function, just not when following conditions 1,2 and 3
同样,1,2和3似乎具有所需的结果。条件4和5起作用,而不是在遵循条件1,2和3时
select [history].[id]
[history].[trans],
CAST([history].[paid_dt] AS Date),
CAST([history].[due_dt] AS Date),
FROM [history]
LEFT OUTER JOIN [information] ON [history].[id] = [information].[id]
--Condition 1--
WHERE NOT ([history].[trans] IN
('TRSF',
'TRR',
'BEG',
'DTR',
'LTC',
))
OR
--Condition 2--
(CONVERT(date,[paid_dt]) = '2015-12-30'
AND [trans] = 'ADJE')
OR
-- Condition 3--
([history].[paid_dt] = [information].[date]
AND [history].[trans] LIKE '%ADJE%'
AND [history].[due_dt] < '2017-01-01')
--Condition 4--
OR
(datepart(dd, [paid_dt]) = 8)
--assume there is more to this condition--
OR
--Condition 5--
(CONVERT(date,[history].[paid_dt]) = '2018-01-08'
and [history].[trans] = 'MANR'));
Just looking for insight as how to address
只是寻找洞察力如何解决
1 个解决方案
#1
1
'NOT' acts only on one condition. If you don't want any of the other conditions to be returned if true... try surrounding all conditions following the 'NOT' keyword in parentheses. Also, double check where you have your parentheses. I'm still seeing an odd number of those maybe due to pasting.
'NOT'仅对一种情况起作用。如果您不希望返回任何其他条件,如果为true,请尝试围绕括号中“NOT”关键字后面的所有条件。另外,仔细检查括号中的位置。我仍然看到奇怪的数量可能是由于粘贴。
WHERE NOT
(
(Condition 1)
OR
(Condition 2)
)
You can also try getting away from the 'NOT' keyword by using <> references instead.
您也可以尝试使用<>引用来远离'NOT'关键字。
#1
1
'NOT' acts only on one condition. If you don't want any of the other conditions to be returned if true... try surrounding all conditions following the 'NOT' keyword in parentheses. Also, double check where you have your parentheses. I'm still seeing an odd number of those maybe due to pasting.
'NOT'仅对一种情况起作用。如果您不希望返回任何其他条件,如果为true,请尝试围绕括号中“NOT”关键字后面的所有条件。另外,仔细检查括号中的位置。我仍然看到奇怪的数量可能是由于粘贴。
WHERE NOT
(
(Condition 1)
OR
(Condition 2)
)
You can also try getting away from the 'NOT' keyword by using <> references instead.
您也可以尝试使用<>引用来远离'NOT'关键字。