Declare @Table Table (OrderNo int, [LineNo] int, Product varchar(50), Result varchar(50))Insert Into @TableSelect 1,1, 'ABC', NULL UNION ALLSelect 1,2, 'XYZ', 'Requires Review' UNION ALLSelect 2,1, 'FooBar', NULL UNION ALLSelect 2,2, 'ID10t', NULL Select * from @Tablewhere OrderNo Not IN (Select OrderNo From @Table Where Result IS NOT NULL)
create table #Orders ( OrderNum int, LineNum int, Product varchar(10), Result varchar(25));insert into #Ordersselect 1,1,'ABC',null union allselect 1,2,'XYZ','Requires Review' union allselect 2,1,'Foobar',null union allselect 2,2,'Id10t',null;select * from #Orders;with OrderResults( OrderNum) as (select distinct OrderNumfrom #Orderswhere Result is not null)select o.OrderNum, o.LineNum, o.Product, o.Resultfrom #Orders o left outer join OrderResults ors on (o.OrderNum = ors.OrderNum)where ors.OrderNum is null;drop table #Orders;
create table #Orders ( OrderNum int, LineNum int, Product varchar(10), Result varchar(25));insert into #Ordersselect 1,1,'ABC',null union allselect 1,2,'XYZ','Requires Review' union allselect 2,1,'Foobar',null union allselect 2,2,'Id10t',null union allselect 3,1, 'ABC', 'Not Null' union allselect 3,2, 'DEF', 'Not Null';
-- Get the orders where all Result is nullSELECT OrderNumFROM #OrdersGROUP BY OrderNumHAVING COUNT(Result) = 0
-- You can also get all of the orders that don't-- have any nulls in ResultSELECT OrderNumFROM #OrdersGROUP BY OrderNumHAVING COUNT(*) - COUNT(Result) = 0