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
 General SQL Server Forums
 New to SQL Server Programming
 Weird Date ordering behaviour

Author  Topic 

velnias2010
Posting Yak Master

125 Posts

Posted - 2011-05-04 : 09:27:27
I have the following query

SELECT *
FROM tbHRI_Race AS r INNER JOIN
tbHRI_Meeting AS m ON r.MeetingNum = m.MeetingNum INNER JOIN
tbHRI_Venue AS v ON v.RA_Venue_id = m.RA_Venue_id
WHERE (r.ResultsIn = 'Y') AND (r.RA_race_cancelled_ind_id <> 'Y')
ORDER BY m.RA_Meeting_Date_dt DESC

In which RA_Meeting_Date_dt is a datetime

Now the issue is, that it doesnt seem to be ordering correct i.e

2011-04-29 00:00:00.000

is above

2011-05-03 00:00:00.000

how could this be possible ?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-04 : 09:30:21
April 29th comes before May 3rd.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-04 : 09:31:28
P.S. You may need to SET DATEFORMAT mdy or whatever.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

velnias2010
Posting Yak Master

125 Posts

Posted - 2011-05-04 : 09:32:31
Yup I know this.

But I have I ask for Date descending I would want

May 3rd
April 29th

My question was why am I getting back

April 29th
May 3rd
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-04 : 09:35:23
RA_Meeting_Date_dt confirm is a datetime ?

If the ordering is as what you said, it looks to me that the column is a string


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2011-05-04 : 23:09:52
You've clearly editied it. Can you post the actual query & output?
Have you removed a TOP clause anywhere before posting? If so that could be the cause of your problem.
Go to Top of Page
   

- Advertisement -