我想查询电话1和电话2代码都不包含"移动"一词的数据。 尝试了 AND 和 OR 语句,但当其中一个字段中存在"MOBILE"时,它不起作用。
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')
你想要的逻辑是:
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')