I want return records from two database tables when a record differs in at least one of the fields.
I have written a query for it using the UNION
operator. It is working absolutely fine.
However, I want to treat NULL and '' (empty string) as the same value.
For example, all entries have a field Email-ID
having value NULL
in one table and ''
in the other table.
Using the query I have, it is showing these two are different. I want these two values to be treated the same. I have around 15 such fields.
How do I do this?
1 Answer 1
Use ISNULL or COALESCE
SELECT COALESCE(A.NULLABLEFIELD,'') FROM A
UNION
SELECT COALESCE(B.NULLABLEFIELD,'') FROM B
-
Thanks. Just got it before your reply. Your reply made me confident about the solution. Thanks for the reply.Raj Wadhwa– Raj Wadhwa2012年07月11日 06:54:23 +00:00Commented Jul 11, 2012 at 6:54
-
I used UNION to get that problem solved. Now what I want is to treat "raj" and "Raj" as different string values. Can I do it?Raj Wadhwa– Raj Wadhwa2012年07月13日 07:38:03 +00:00Commented Jul 13, 2012 at 7:38
-
2Change collation type to Latin1_General_CS_ASWOPR– WOPR2012年07月17日 07:46:39 +00:00Commented Jul 17, 2012 at 7:46