在这两个地方都可以找到东西

时间:2017-04-05 21:28:49

标签: sql sql-manager

我想查询数据,其中phone1和phone2代码不包含“移动”字样。尝试过AND和OR语句,但在“移动”和“移动”时无效。存在于其中一个领域。

    select ORDCON.* from PL00.dbo.ordhdr inner join PL00.dbo.ordhdrx on ordhdrx.ORDER_NO = ordhdr.ORDER_NO
                               INNER JOIN PL00.dbo.schedule on schedule.ID_VAL = ordhdr.ORDER_NO
                              left outer join PL00.dbo.ordcon on ordcon.ORDER_NO = ordhdr.ORDER_NO
where ordhdr.RSPNS_CODE = 'TXTB4'
and (schedule.[DATE] >= CONVERT(varchar(10), getdate(), 101)) 
AND (NOT ORDCON.PHONE1CODE = 'MOBILE' 
OR NOT ORDCON.PHONE2 = 'MOBILE')

1 个答案:

答案 0 :(得分:0)

你想要的逻辑是:

AND (ORDCON.PHONE1CODE <> 'MOBILE' AND ORDCON.PHONE2 <> 'MOBILE')

或者假设两者都不是NULL

AND 'MOBILE' NOT IN (ORDCON.PHONE1CODE, ORDCON.PHONE2)

您确定第二个变量不是ORDCON.PHONE2CODE而不是ORDCON.PHONE2吗?我怀疑是正确的逻辑:

AND (ORDCON.PHONE1CODE <> 'MOBILE' AND ORDCON.PHONE2CODE <> 'MOBILE')