Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 GROUP BY COUNT
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

evanburen
Posting Yak Master

167 Posts

Posted - 02/04/2013 :  23:25:40  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 02/04/2013 :  23:29:49  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000