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?

Hannah Vernon
71k22 gold badges178 silver badges323 bronze badges
asked Jul 11, 2012 at 6:05

1 Answer 1

4

Use ISNULL or COALESCE

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.