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
 General SQL Server Forums
 New to SQL Server Programming
 Simple query just stopped working
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

Posted - 04/23/2013 :  04:11:50  Show Profile  Reply with Quote
Hello there,

can someone help before I smash my laptop up.

I have a simple query that was working yesterday, now its not.

select distinct occasionid
from Ticket_Facts
where OccasionID not in (select OccasionID from Game_Classification)

both occasioned columns are bigint types.

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 04/23/2013 :  04:14:34  Show Profile  Visit webfred's Homepage  Reply with Quote
...and the meaning of "not working" in this case is?
Please give us more information.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/23/2013 :  04:16:58  Show Profile  Reply with Quote
select distinct occasionid
from Ticket_Facts
where OccasionID not in (select OccasionID from Game_Classification WHERE OccasionID IS NOT NULL)


--
Chandu
Go to Top of Page

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

Posted - 04/23/2013 :  04:25:37  Show Profile  Reply with Quote
thank you bandit

lovely
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/23/2013 :  04:27:52  Show Profile  Reply with Quote
quote:
Originally posted by masterdineen

thank you bandi
lovely

welcome
Don't forget to include WHERE colName IS NOT NULL in subquery whenever you decided to use NOT IN

--
Chandu

Edited by - bandi on 04/23/2013 04:28:10
Go to Top of Page

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

Posted - 04/23/2013 :  04:32:50  Show Profile  Reply with Quote
why doesn't it just pick out the matching ids. even tho there is a null.

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/23/2013 :  04:38:25  Show Profile  Reply with Quote
NOT IN clause indirectly puts AND with multiple conditions
from Ticket_Facts
OccasionID not in (select OccasionID from Game_Classification)

i.e.
OccasionId !=ConditionValue1 AND OccasionId !=ConditionValue2 AND OccasionId !=ConditionValue3 ..... AND OccasionId != NULL

So Occasion != NULL returns always zero rows...

--
Chandu
Go to Top of Page

masterdineen
Aged Yak Warrior

United Kingdom
548 Posts

Posted - 04/23/2013 :  05:22:37  Show Profile  Reply with Quote
o thank you for that, learn something new everyday
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 04/23/2013 :  05:46:21  Show Profile  Reply with Quote
quote:
Originally posted by masterdineen

o thank you for that, learn something new everyday


Welcome

--
Chandu
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.06 seconds. Powered By: Snitz Forums 2000