# Databases > SQL MAX(Date) Function SQL Server

## sonyshah

Hi, 

Iave this SQL that should return recors with MAX(DateTimeCreated). DB has 2 records 1 with 01/31/08 and 1 with 01/18/2008. My SQL is returning 01/18/2008; I do not know why? Can someone guide me please? Thanks 

select ejhcoid,ejheeid,
max(ejhdatetimecreated) as maxdatetimecreated
      from ULTIPRO_FREE.dbo.EmpHJob
      where 
     EjhEmplStatus <> 'T' and 
   ejhdatetimecreated between '2008/01/01' and '2008/01/31'and 
	ejhisratechange = 'Y' and 
	 ejheeid = '5U8FX30000K0'
      group by ejhcoid,ejheeid

----------


## debasisdas

Does both the records satisfy the condition in the where clause of the query ?

----------


## krishnaindia2007

select ejhcoid,ejheeid,
max(ejhdatetimecreated) as maxdatetimecreated
from ULTIPRO_FREE.dbo.EmpHJob
where 
EjhEmplStatus <> 'T' and 
ejhdatetimecreated between '2008/01/01' and '2008/01/31'and 
*ejhisratechange = 'Y'* and 
ejheeid = '5U8FX30000K0'
group by ejhcoid,ejheeid 

Problem may be with ejhisratechange. Both the records may not satisfy this codition.

----------


## peeyush_jain

Hi, your looks correct and as you call aggreagate function is also correct , please check with DB if both the records have same fields.

----------

