Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2007, 06:52 PM
Authorized User
 
Join Date: Mar 2005
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Default Returnig records on EXIST

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:
Code:
                                                                                                                                                                       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



 
Old January 2nd, 2007, 08:17 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in updating records & finding records naveed77 VB Databases Basics 1 January 16th, 2007 12:12 PM
problem in updating records & finding records naveed77 VB How-To 1 January 16th, 2007 12:10 PM
record exist or not keyvanjan Classic ASP Basics 2 May 5th, 2006 11:39 AM
Find records that don't exist harg7769 MySQL 0 April 28th, 2005 10:44 AM
Find records that don't exist harg7769 Access 1 April 20th, 2005 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.