As an example, if I have a table:
DECLARE @tmpTable TABLE
( SectionID INT,
DetailID INT)
I have the following data:
SectionID DetailID
1000 -1
1000 0
1000 -1
1100 5000
1100 0
1200 0
1200 0
1300 7000
1300 8000
How do I write the SQL to get all Section Ids that have ALL Detail IDs of 0 or -1. In the above example, the SQL should return 1000 and 1200 (not 1100 as atleast 1 item is not a 0 or a -1)
I think this should work too, since
DetailIDis an integer and the values you are checking (-1and0) have no gaps between them. And it could be faster, with an index on(SectionID, DetailID):