mike55 Posted January 7, 2008 Posted January 7, 2008 I have a datetime column in a table, I am performing a select statement on the table and ordering by the datetime column. Previously the order of the data was correct as all the dates were in 2007. However the last few days have seen the introduction of 2008 dates. As a result, the order of the dates as slightly off in that 2008 dates appear at the bottom of the list while 2007 dates appear at the top. Here is the query that I am using: SELECT dbo.Timesheets.Id, CONVERT(varchar, dbo.Timesheets.[Date], 103) AS [Date], dbo.Timesheets.Hours, dbo.Timesheets.Comments, dbo.Timesheets.Offsite, dbo.ParentProjects.Name as Parent, dbo.ChildProject.Name as Child, dbo.Timesheets.Hour, dbo.Timesheets.Minute, CONVERT(varchar, Hour) + ':' + CONVERT(varchar, Minute) AS times FROM dbo.Timesheets INNER JOIN dbo.StaffList ON dbo.Timesheets.Employee = dbo.StaffList.EmployeeId INNER JOIN dbo.ParentProjects ON dbo.Timesheets.Parent = dbo.ParentProjects.ProjectID INNER JOIN dbo.ChildProject ON dbo.Timesheets.Child = dbo.ChildProject.MProjectID WHERE (dbo.StaffList.Username = @Employee) ORDER BY dbo.Timesheets.[Date] DESC, Id Desc, times Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
mike55 Posted January 7, 2008 Author Posted January 7, 2008 Solved the problem, by changing the order by statement to the following: ORDER BY DATEDIFF(WEEK, '2003-05-24', dbo.Timesheets.Date) DESC, Id Desc, times Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted January 7, 2008 Administrators Posted January 7, 2008 What data type are the dates stored as? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.