Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 strange results with max function and dates

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-08 : 04:16:27
i am making this select :

select userid,entrnacedate
from userentrence
where userid=4
order by entrnacedate desc

and i get everything ok
when i do :

select userid,MAX(entrnacedate) as maxEnter
from userentrence
where userid=4
group by userid


i get a wronmg result!
the result isnt the max date at all!
howcan this be?
the entrnacedate is a dateime type.
should i do a max query on a date in another way?

the more strange thing that on some of the users it works great
and on some it gives incorrect resut!

thnaks in avance
peleg


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-03-08 : 04:44:00
What result are you getting? Can you post your DDL and sample data that you are working with. So long as this field is defined as a datetime, I can't see a problem.

Mark
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-03-08 : 04:49:09
"the entrnacedate is a dateime type"

Worth just double checking that ... 'coz I can't see how you would get the wrong answer otherwise!

Kristen
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-08 : 08:00:50
well not my mistake execlly
the one who wrote the code before didnt update the tables correctly
appologizeing

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page
   

- Advertisement -