There are several records in the same OrderNo, if GoodsCode of one of them is '7777000100010', I have to select it, if no such record, select any one of else.my SQL as below, now I got result but they are not distinct with same OrderNo, I want to get distinct result, what can I modify my SQL?SELECT DISTINCT convert(varchar,convert(datetime,[RegisterData]),111)as [RegisterDate],[ExportNo],[OrderNo], [ArriveDate] = case [GoodsCode] when '7777000100010' THEN 'No' ELSE [ArriveDate] END, [Name], [GoodsCode] = case [GoodsCode] when '7777000100010' THEN 'TodayArrive' ELSE 'ArriveOnDate' ENDFROM [myTable](nolock) order by RegisterData desc