Try
SELECT * FROM mytable mt1
WHERE Status IN (5,7) AND ncic LIKE 't%'
AND NOT EXISTS ( SELECT * FROM mytable mt2
WHERE mt1.ncic = mt2.ncic AND mt1.Status <> mt2.status)
>I would like to use one query to accomplish the following:
>
>We have a table in MS SQL Server that is populated when an entry is made on a possible stolen vehicle. there is a status field that will have either a 5 or 7 and a temporary number in the ncic field that starts with 't'followed by 9 other random numbers. There are other records that have other statuses and don't have the 't' in the ncic field. I need to pull everything that doesn't have two records for a given temporary number like the following:
>
>ncic status entry_date
>t12312312 7 01/01/2007
>t12312312 5 01/02/2007
>t12312111 7 01/01/2007
>t12312871 7 01/05/2007
>
>the first two records should not appear in the result set because they have both a 7 and a 5, with a matching ncic number. I was thinking a subquery might be in order, otherwise, I'll have to do it in two steps.
--sb--