问题描述
我有以下握手表:
CREATE TABLE [dbo].[Handshake](
[Report Year] [varchar](100) NULL,[Status] [varchar](100) NULL,[Update Time] [datetime] NULL,[Process Time] [datetime] NULL,[Rejects?] [varchar](10) NULL
) ON [PRIMARY]
GO
如果我运行此查询,
SELECT TOP (1) *
FROM [dbo].[Handshake]
WHERE [Status] <> 'Loading' OR [Status] <> 'Processing' OR [Status] <> 'Processed' OR [Status] <> 'Process Failed'
ORDER BY [Update Time] DESC
我希望WHERE子句中指示的任何内容都不会返回,但是它是!!
例如,Processed
记录不应该被返回!!
这就是我得到的:
样本数据
Report Year Status Update Time Process Time Rejects?
2020 8+4 Processed 2020-10-09 16:58:05.610 2020-10-09 17:20:05.000 NULL
2020 8+4 Processed 2020-10-09 16:22:06.343 2020-10-09 16:53:26.000 NULL
2020 5+7 Processed 2020-09-29 18:09:00.000 2020-10-09 16:04:04.000 TRUE
2020 6+6 Failed 2020-09-29 17:21:00.000 NULL NULL
2020 5+7 Processed 2020-09-29 15:54:00.000 2020-10-09 16:04:04.000 NULL
解决方法
您似乎想要AND
,而不是OR
:
WHERE [Status] <> 'Loading'
AND [Status] <> 'Processing'
AND [Status] <> 'Processed'
AND [Status] <> 'Process Failed'
您也可以使用not in
来表达这一点:
WHERE [Status] NOT IN ('Loading','Processing','Processed','Process Failed')