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
 not in
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

389 Posts

Posted - 07/11/2013 :  04:53:34  Show Profile  Reply with Quote
i have ID number and status.

how can i not include those status which has closed?

i tried to use not in but did not work.

ID status
1 new
1 old
1 closed
2 new
2 old
3 new
3 old

i tried select * from tableA where Status not in ('closed')
and I get as below:

ID status
1 new
1 old
2 new
2 old
3 new
3 old

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/11/2013 :  05:00:04  Show Profile  Reply with Quote
do you mean this then?


SELECT t.* 
FROM Table t
INNER JOIN (SELECT ID
            FROM Table
            GROUP BY ID
            HAVING SUM(CASE WHEN status='closed' THEN 1 ELSE 0 END)=0
           )t1
On t1.ID = t.ID


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

peace
Constraint Violating Yak Guru

389 Posts

Posted - 07/11/2013 :  05:21:12  Show Profile  Reply with Quote
I meant those with 'closed' status will not grab the whole ID.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/11/2013 :  05:25:26  Show Profile  Reply with Quote
quote:
Originally posted by peace

I meant those with 'closed' status will not grab the whole ID.


Thats exactly what suggestion i gave does. Did you try it?

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

peace
Constraint Violating Yak Guru

389 Posts

Posted - 07/11/2013 :  05:37:41  Show Profile  Reply with Quote
Ya i tried.
But the id with 'closed' still included.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/11/2013 :  05:48:42  Show Profile  Reply with Quote
quote:
Originally posted by peace

Ya i tried.
But the id with 'closed' still included.


it wont if you use it as suggested

show your code plese

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

peace
Constraint Violating Yak Guru

389 Posts

Posted - 07/11/2013 :  05:56:47  Show Profile  Reply with Quote
sorry it works fine now.

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/11/2013 :  05:58:24  Show Profile  Reply with Quote
quote:
Originally posted by peace

sorry it works fine now.

Thanks


So what went wrong last time?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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