mrmcg
mrmcg

Reputation: 191

Select multiple rows with the same value, but one column not the same but is blank

I am trying to do is get the records that have more than the same PartID but have a field that is blank and the other is not. SQL Server 2014.

SELECT COUNT(*), imbPartID 
FROM PartBins 
WHERE imbPartBinID = ''
GROUP BY imbPartID 
HAVING COUNT(*) > 1

Results:

imbPartID    imbPartLocation
----------------------------
11111        333-30
11111        320-12
22222
22222        243-43
33333        434-21
33333        122-09
44444
44444        651-04

etc...

So the results will show.

Column1      imbPartID
2            22222
2            44444

Upvotes: 0

Views: 67

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271141

I think you want:

SELECT COUNT(*), imbPartID
FROM PartBins 
GROUP BY imbPartID
HAVING SUM(CASE WHEN imbPartBinID = '' THEN 1 ELSE 0 END) > 0;

Upvotes: 1

Related Questions