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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Finding one in a group

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2015-04-07 : 14:05:08
I have a groups of data like in the example below and I want to identify the borrower numbers where none of their tag values = 'dNoRehab'. So in this example, this borrower number would not be in the results because one of the tag values = 'dNoRehab'



This is what I have but it's not working for me

SELECT DISTINCT [Part1].BorrowerNumber
FROM [Part1]
WHERE [Part1].Tag NOT IN
(SELECT [Part1].BorrowerNumber FROM [Part1] WHERE [Part1].Tag = 'dNoRehab')

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-04-07 : 14:16:19
It's because you are using the wrong column here: WHERE [Part1].Tag. Switch it to BorrowerNumber. I would use NOT EXISTS though.


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

evanburen
Posting Yak Master

167 Posts

Posted - 2015-04-07 : 14:26:40
Ah, Geez. Thanks


quote:
Originally posted by tkizer

It's because you are using the wrong column here: WHERE [Part1].Tag. Switch it to BorrowerNumber. I would use NOT EXISTS though.


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/

Go to Top of Page
   

- Advertisement -