Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Anybody know how to use the In Operator in the select stmt when one of the values is NULL? Here is my code:select * from Clientwhere AgencyId is not null --and AgencyName is not nulland left(controlnumber,2)<>'72'and left(controlnumber,2) <>'13'and CPAFirmId IN ('0','',NULL)Since the IN operator requires all values to be in quotes, it does not work properly when NULL is specified. I also tried 'NULL' but that gives an error.
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2007-06-26 : 17:31:20
IN operator does not require values to be in quotes.Tara Kizerhttp://weblogs.sqlteam.com/tarad/
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts
Posted - 2007-06-26 : 17:38:03
This makes no sense, because CPAFirmId can never be equal to NULL:
CPAFirmId IN ('0','',NULL)
Try this instead:
( CPAFirmId IN ('0','') or CPAFirmId is null )
If CPAFirmId is actually an integer, you should remove the quotes.CODO ERGO SUM
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2007-06-27 : 00:18:25
orcoalesce(CPAFirmId,'') in ('0','')MadhivananFailing to plan is Planning to fail