2

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

4

Use ISNULL or COALESCE

SELECT COALESCE(A.NULLABLEFIELD,'') FROM A
UNION
SELECT COALESCE(B.NULLABLEFIELD,'') FROM B
3
  • Thanks. Just got it before your reply. Your reply made me confident about the solution. Thanks for the reply.
    – Raj Wadhwa
    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
    Jul 13, 2012 at 7:38
  • 2
    Change collation type to Latin1_General_CS_AS
    – WOPR
    Jul 17, 2012 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.