在其中搜索Muliple项目的子句

发布于 2025-02-04 01:09:59 字数 712 浏览 1 评论 0原文

我有一个具有问题名称字段和管辖权名称字段的表。我想搜索属于同一管辖权名称的多个问题名称。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说不完的你爱 2025-02-11 01:09:59

在这些情况下,它始终是条件。操作员的优先级在您认为应有的方式上无法正常工作。您需要括号:

  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')

但是,由于这两个检查中的任何一个都没有通配符,因此我们也可以这样简化它:

  where Jurisdiction like 'Sector 5%' 
    and Response_Date >= '2022-01-01 00:00:00.000' 
    and Problem IN ('Building / Security Check-LCL','Park and Walk-LCL')

It's always the OR condition in these cases. Operator precedence here doesn't work the way you think it should. You need parentheses:

  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')

But since there are no wildcards in either of those checks, we can also simplify it like this:

  where Jurisdiction like 'Sector 5%' 
    and Response_Date >= '2022-01-01 00:00:00.000' 
    and Problem IN ('Building / Security Check-LCL','Park and Walk-LCL')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文