>iId cEDP nPVC nSVC dUpdatedOn >1 123 10.12 15.30 12/1/2008 >2 123 12.12 0.00 12/2/2008 >3 555 35.40 0.00 12/2/2008 >>
; with CTE_0 as (select * from myTable where nPVC = 0 or nSVC = 0) select myTable.* inner join (select MAX(dUpdatedOn) as MaxDate, cEDP from myTable group by cEDP where cEDP not in (select cEDP from CTE_O)) MaxDate on myTable.cEDP = MaxDate.cEDP and myTable.dUpdateOn = MaxDate.MaxDate UNION ALL select * from CTE_0Of course, you can do it without CTE using it as a derived table.