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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Show rows with a certain column value/string

Author  Topic 

atompaaa
Starting Member

2 Posts

Posted - 2010-11-30 : 05:23:10
Hello!

I´m making this query into a temporary table, now I want to make the result list a little shorter.

Sample of result from the temp table with no where or group or anything:
____
Artnr | Place | OK or Not

99999000055 01010201 Not OK
99999000055 01010201 Not OK
99999000055 01010201 OK
99999000055 01010201 OK
99999000055 01010201 OK
42037901104 01010203 OK
42037901104 01010203 OK
_____

then it goes on..

What I want is to make a query against the temp table where the result is to only show the "Artnr"´s where "OK or Not" is OK on all its lines. In the result above I would´ve liked it to only show 42037901104 on one line. How can I do this?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-30 : 05:29:30
select DISTINCT Artnr from table as t1 where [OK or Not] = 'OK'
and not exists(select * from table as t2 where t2.Artnr=t1.Artnr and [OK or Not] = 'Not OK')


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

atompaaa
Starting Member

2 Posts

Posted - 2010-11-30 : 05:47:18
That worked very nice, thank you!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-30 : 07:26:56
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -