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.
Author |
Topic |
evanburen
Posting Yak Master
167 Posts |
Posted - 2013-07-16 : 16:03:41
|
I have data like thisBorrowerNumber TagName1 bPCARecl1 bThisOne1 bThatOne2 bThisOne2 bThatOne2 bPCARecl3 bThisOne 3 bThatOne4 bPCAReclI want to find individual Borrower Numbers where any one of the group <> 'bPCARecl'DISTINCT lists every row where tag name <> 'bPCARecl' but it doesn't tell me if any one row for a group of borrower numbers <> 'bPCARecl'My code returns only rows where there is only one record (4 in my example data)SELECT BorrowerNumberFROM AdminsWHERE TagName <> 'bPCARecl'GROUP BY BorrowerNumberHAVING (Count(TagName)=1)I would want the results to return BorrowerNumber 3 it is the only one none of the rows in that group of Borrower Numbers does not contain TagName of 'bPCARecl'Thanks |
|
ScottPletcher
Aged Yak Warrior
550 Posts |
Posted - 2013-07-16 : 16:18:29
|
[code]SELECT BorrowerNumberFROM dbo.AdminsGROUP BY BorrowerNumberHAVING MAX(CASE WHEN TagName = 'bPCARecl' THEN 1 ELSE 0 END) = 0[/code] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-07-17 : 04:52:52
|
if you want entire columns to be returned in resultset you need something like thisSELECT BorrowerNumber, TagNameFROM(SELECT *,SUM(CASE WHEN TagName = 'bPCARecl' THEN 1 ELSE 0 END) OVER (PARTITION BY BorrowerNumber) AS CntFROM dbo.Admins)tWHERE Cnt = 0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|