[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

sort by date and time in SQL

Posted on 2013-10-30
3
Medium Priority
?
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 2000 total points
ID: 39610878
You need to change your cast to:

CAST(AUDIT.CompletedDate AS datetime)

Open in new window

0
 

Author Closing Comment

by:AZZA-KHAMEES
ID: 39610883
thanks
0
 
LVL 49

Expert Comment

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

650 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