Results 1 to 4 of 4

Thread: MAX(Date) Function SQL Server

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Answers
    3

    MAX(Date) Function SQL Server

    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


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: MAX(Date) Function SQL Server

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


  3. #3
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: MAX(Date) Function SQL Server

    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.


  4. #4
    Expert Member
    Join Date
    Dec 2007
    Answers
    138

    Re: MAX(Date) Function SQL Server

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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact