Please help. The query is as far as I can get. Here is the query in txt format. Since the max(EndMeasDepth) is NULL or 0, I want to get the column [ToTime] with min(ReportNo) and min(SeqNO)
Query:
select D.wellid, min(ToTime) as [ToTime]from
DailyOperations d
INNER JOIN (select WellID, max(ISNULL(EndMeasDepth,0)) AS MaxEndMeasDepth
from DailyOperations Group By WellID) DM on DM.WellID = D.WellID and
DM.MaxEndMeasDepth = ISNULL(D.EndMeasDepth,0)
where D.JobID ='Drilling' and D.wellid ='102193.01'
GROUP BY D.WellID
order by D.WellID