SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 NOT IN in SQL Query Result not Shown
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

raguyazhin
Posting Yak Master

India
105 Posts

Posted - 12/28/2013 :  02:41:45  Show Profile  Reply with Quote

Hi,

Result Not Shown in NOT IN Used Query.

The First Query Return 1 Row for the criteria

select * from RE_SURGERY_SCHEDULE where RSS_SURGERY_SCHEDULE_NUM='SG10131212/0003'


The Second Query Return 0 Row for the criteria

select * from WA_ADMISSION_TXN where WAT_SURGERY_SCHEDULE_NUM='SG10131212/0003'
Here I combine two queries but result not shown what is mistake in this query

select * from RE_SURGERY_SCHEDULE
where RSS_SURGERY_SCHEDULE_NUM not in (
select WAT_SURGERY_SCHEDULE_NUM from WA_ADMISSION_TXN)



--
Ragu

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/28/2013 :  03:18:26  Show Profile  Reply with Quote
you should be using NOT EXISTS I guess

select * from RE_SURGERY_SCHEDULE r
where NOT EXISTS(
select 1 from WA_ADMISSION_TXN WHERE r.RSS_SURGERY_SCHEDULE_NUM = WAT_SURGERY_SCHEDULE_NUM 
) 



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 12/28/2013 :  09:31:26  Show Profile  Reply with Quote

select * from RE_SURGERY_SCHEDULE
where RSS_SURGERY_SCHEDULE_NUM not in (
select WAT_SURGERY_SCHEDULE_NUM from WA_ADMISSION_TXN)


will fail if the inner SELECT returns a NULL.

Does this return any rows?

select TOP 100 *
from WA_ADMISSION_TXN
WHERE WAT_SURGERY_SCHEDULE_NUM IS NULL

Edited by - Kristen on 12/28/2013 09:31:54
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000