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)
 GROUP BY COUNT

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2013-02-04 : 23:25:40
I have a list of BorrowerNumbers grouped by that field. I want to count the number of groups which don't have the TagName value of "dDirect" in it. So in this example with BorrowerNumber 1102469 I don't want to count this group because at least one record has dDirect in the TagName. I have many other groups with different BorrowerNumbers without dDirect and I want to identify these groups. Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-04 : 23:29:49
the below code will give you the borrownumber groups without dDirect tag in them

SELECT *
FROM
(
SELECT *,COUNT(CASE WHEN TagName = 'dDirect' THEN 1 ELSE NULL END) OVER (PARTITION BY BorrowNumber) AS DirectCnt
FROM Table
)t
WHERE DirectCnt=0


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -