clear markdown compare help best fiddles feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3601600 fiddles created (48016 in the last week).

select @@version;
(No column name)
Microsoft SQL Server 2019 (RTM-CU1) (KB4527376) - 15.0.4003.23 (X64) Dec 6 2019 14:53:33 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
 hidden batch(es)


create table TestTable (id int, FromDt Date, ToDt Date) Insert into TestTable Values (1, NULL, NULL), (1, NULL, NULL), (1, '2019-01-01', '2019-01-01'), (2, NULL, NULL), (2, NULL, NULL), (3, NULL, NULL), (1, '2019-02-01', '2019-02-01') Select distinct Id From TestTable where FromDt is null and ToDt is null and id not in (Select t.Id from TestTable t where t.fromDt is not null and t.toDt is not null)
Id
2
3
 hidden batch(es)