Subject: Returnig records on EXIST
Posted By: ninel Post Date: 1/2/2007 5:52:08 PM
I have two tables: A and B. A is the main table and B is the exception table. What I need to do is check if anything in Table A exists in table B based on a couple of fields.

Ex:
                                                                                                                                                                       SELECT [sCustomerFullName], [sAccountNumber], [sSIM], [sPlanCode]FROM A a                                                                                                                                                                    WHERE EXISTS  (SELECT * FROM B b  WHERE a.ssim = b.sSim AND a.sTMobilePlanCode = b.sTMobilePlanCode)


Let's say Table A contains custname(Joe Shmoe), but the sSIM is empty (because the table doesn't allow NULL values). This customer DOES NOT exist in table B. This record shouldn't be returned because it doesn't exist in table B, but it is  being returned because the sSIM is empty.

I played with my own copy of the table A and set up sSIM as allowing NULL values. Using the query above did not return the record.

Does anyone know how to get around this if the field does not allow NULLs?

Thanks,
Ninel



 

Reply By: Jeff Moden Reply Date: 1/2/2007 7:17:58 PM
Why not do just an inner join?

Also, if you don't mind... please preview your posts and make sure that we can actually see all of your code without having to scroll to the right so far.  Thanks.

--Jeff Moden

Go to topic 54273

Return to index page 76
Return to index page 75
Return to index page 74
Return to index page 73
Return to index page 72
Return to index page 71
Return to index page 70
Return to index page 69
Return to index page 68
Return to index page 67