比较何时值可以是NULL或文本

m.e*_*son 5 sql t-sql sql-server sql-server-2005

现在我知道你不能直接将NULL与任何东西进行比较(因为null是未知的)所以我将如何实现以下目标:

select  *
    from    Material as m
    where   MtrlCode = 826 and
            Exposlimit <> 'compareMe'
Run Code Online (Sandbox Code Playgroud)

Exposlimit可能为NULL或者可能不是.'compareMe'也可能为NULL.

因此,我如何比较两者?双方可以是文本也可以是NULL.

Red*_*ter 5

select  * 
from    Material as m 
where   MtrlCode = 826 
    and (Exposlimit <> 'compareMe'
         or (Exposlimit is null and compareme is not null) 
         or (Exposlimi is not null and compareme is null))
Run Code Online (Sandbox Code Playgroud)