Geeks Talk

Prepare for your Next Interview




MAX(Date) Function SQL Server

This is a discussion on MAX(Date) Function SQL Server within the SQL forums, part of the Databases category; 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 ...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-12-2008
Junior Member
 
Join Date: Jun 2008
Location: Irvine
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
sonyshah is on a distinguished road
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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-13-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 125 Times in 112 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: MAX(Date) Function SQL Server

Does both the records satisfy the condition in the where clause of the query ?
Reply With Quote
  #3 (permalink)  
Old 06-13-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
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.
Reply With Quote
  #4 (permalink)  
Old 06-16-2008
Expert Member
 
Join Date: Dec 2007
Location: Pune
Posts: 139
Thanks: 0
Thanked 6 Times in 6 Posts
peeyush_jain is on a distinguished road
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.
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Function in datastage to find date after 6 months Geek_Guest Database General 4 09-22-2008 03:17 PM
Adding storage function to a mail server satimis Database General 0 01-04-2008 03:54 AM
romise date, Need by date, Original Date in PO Geek_Guest Oracle Apps 0 04-07-2007 12:53 AM
Date Function in Oracle Robert Oracle 4 02-16-2007 06:15 AM
SQL Server Replace Function suji SQL Server 1 01-30-2007 12:54 PM


All times are GMT -4. The time now is 02:57 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved