Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Use ISNULL or COALESCE

SELECT COALESCE(A.NULLABLEFIELD,'') FROM A
UNION
SELECT COALESCE(B.NULLABLEFIELD,'') FROM B
share|improve this answer
    
Thanks. Just got it before your reply. Your reply made me confident about the solution. Thanks for the reply. –  Raj Wadhwa Jul 11 '12 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 '12 at 7:38
    
Change collation type to Latin1_General_CS_AS –  WOPR Jul 17 '12 at 7:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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