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 2005 Forums
 Transact-SQL (2005)
 Select Query help

Author  Topic 

srujanavinnakota
Starting Member

34 Posts

Posted - 2011-01-27 : 14:47:02
Want help with the Select query.
I want to select the AYID's Where all of the AIDID Flags are TRUE.
Below is the Sample data

AidID AYID Flag
7935427 7385823 FALSE
8190980 7385823 TRUE
7935422 7385823 TRUE

I tried below query
Select AYID From test where Flag<>'False'
I want the query to return NULL Because all the values of the Flag should be TRUE for that AYID

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-01-27 : 15:15:16
SELECT t1.*
FROM
yourTable t1

INNER JOIN
(
select AYID,Flag,[Rank] = dense_rank() over(partition by ayid order by flag)
from yourTable
) t2

ON
t1.ayid = t2.ayid

WHERE t2.[rank] = 1
and t2.flag = 'TRUE'

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

srujanavinnakota
Starting Member

34 Posts

Posted - 2011-01-27 : 16:44:33
Thanks So much. It worked...
Go to Top of Page
   

- Advertisement -