Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-07-11 : 04:53:34
|
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 status1 new1 old1 closed2 new2 old3 new3 oldi tried select * from tableA where Status not in ('closed')and I get as below:ID status1 new1 old2 new2 old3 new3 old |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-11 : 05:00:04
|
do you mean this then?SELECT t.* FROM Table tINNER JOIN (SELECT ID FROM Table GROUP BY ID HAVING SUM(CASE WHEN status='closed' THEN 1 ELSE 0 END)=0 )t1On t1.ID = t.ID ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-07-11 : 05:21:12
|
I meant those with 'closed' status will not grab the whole ID. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-11 : 05:25:26
|
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-07-11 : 05:37:41
|
Ya i tried.But the id with 'closed' still included. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-11 : 05:48:42
|
quote: Originally posted by peace Ya i tried.But the id with 'closed' still included.
it wont if you use it as suggestedshow your code plese------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2013-07-11 : 05:56:47
|
sorry it works fine now.Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-11 : 05:58:24
|
quote: Originally posted by peace sorry it works fine now.Thanks
So what went wrong last time?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|