I'm working on returning the most recent history record for a specific contact. I tried the MAX(CompletedDate) to no avail so I thought I'd try the TOP 1 method. When I change it to TOP 2 notice that the second row is a more recent date than the first row. Changing the query to TOP 1 returns the record for 20040326.
20040326 2004-03-26 20:00:00.000
20060821 2006-08-21 00:37:41.000
Anyone have a clue why the 2004 record is returning before the 2006 record? Any ideas would be greatly appreciated. I'm sure the solution is probably the reason the MAX() function is also not working.
Code:
select top 2 convert(char,completeddate,112)as CompletedOn, completeddate, *
from history
where contactid = 'CJPPIA00004A'
and type not in ('262156','262150','262151','262158','262160')
order by completedon
20060821 2006-08-21 00:37:41.000
Anyone have a clue why the 2004 record is returning before the 2006 record? Any ideas would be greatly appreciated. I'm sure the solution is probably the reason the MAX() function is also not working.