在其中搜索Muliple项目的子句
我有一个具有问题名称字段和管辖权名称字段的表。我想搜索属于同一管辖权名称的多个问题名称。
SELECT TOP (100000) [Master_Incident_Number]
,[Response_Date]
,[Problem]
,[Location_Name]
,[Address]
,[Apartment]
,[City]
,[Jurisdiction]
,[MethodOfCallRcvd]
,[Call_Disposition]
,[CallTaking_Performed_By]
,[CallClosing_Performed_By]
FROM [Reporting_System].[dbo].[Response_Master_Incident]
where Jurisdiction like 'Sector 5%'
and Response_Date >= '2022-01-01 00:00:00.000'
and Problem like 'Building / Security Check-LCL'
or Problem like 'Park and Walk-LCL'
当我运行此操作时,我会得到与我为义务司法管辖区(例如'5%'''的管辖权所投入的内容的回报。 。
。
I have a table that has a problem name field and a Jurisdiction name field. I want to search for multiple problem names that fall under the same Jurisdiction name.
SELECT TOP (100000) [Master_Incident_Number]
,[Response_Date]
,[Problem]
,[Location_Name]
,[Address]
,[Apartment]
,[City]
,[Jurisdiction]
,[MethodOfCallRcvd]
,[Call_Disposition]
,[CallTaking_Performed_By]
,[CallClosing_Performed_By]
FROM [Reporting_System].[dbo].[Response_Master_Incident]
where Jurisdiction like 'Sector 5%'
and Response_Date >= '2022-01-01 00:00:00.000'
and Problem like 'Building / Security Check-LCL'
or Problem like 'Park and Walk-LCL'
When I run this I get returns that don't match what I put in for the Jurisdiction like 'Sector 5%'". How can I get it to only return items with the "Jurisdiction like" field being 'Sector 5%' only.
If I only do a search for only one problem name type, the search works and only returns Jurisdictions with the name like "Sector 5". But If I add an additional problem name type it returns all Jurisdiction Names with those 2 problem name types.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这些情况下,它始终是
或
条件。操作员的优先级在您认为应有的方式上无法正常工作。您需要括号:但是,由于这两个检查中的任何一个都没有通配符,因此我们也可以这样简化它:
It's always the
OR
condition in these cases. Operator precedence here doesn't work the way you think it should. You need parentheses:But since there are no wildcards in either of those checks, we can also simplify it like this: