Solved

sort by date and time in SQL

Posted on 2013-10-30
3
522 Views
Last Modified: 2013-10-30
Hi Expert
i have a varchar column in a table, and this column hold date and time value, i wrote a simple query to sort this column descending, its working but it not seem to sort the time, i tried to convert the field to datetime data type but still it ignoring the time

SELECT  AUDIT.CurrentActor, USR.EngName, AUDIT.ReceivedDate, AUDIT.CompletedDate, AUDIT.Status
FROM tbl_ServiceAudit AUDIT  LEFT OUTER  JOIN pr1.dbo.GetUserDetailsE USR ON USR.PERUserName = AUDIT.CurrentActor 
WHERE AUDIT.ReferenceNo =123291
GROUP BY AUDIT.CurrentActor, USR.EngName, AUDIT.ReceivedDate, AUDIT.CompletedDate, AUDIT.Status
ORDER BY
CAST(AUDIT.CompletedDate AS date)
DESC

Open in new window


any suggestion
0
Comment
Question by:AZZA-KHAMEES
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 500 total points
Comment Utility
You need to change your cast to:

CAST(AUDIT.CompletedDate AS datetime)

Open in new window

0
 

Author Closing Comment

by:AZZA-KHAMEES
Comment Utility
thanks
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
well, really, you should store datetime as datetime :)
less space and way less hassle (such as this one)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now