Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the following query.Both vdate and vtime are varchar fields in table.

SQL
select (isnull(RTRIM(LTRIM(CONVERT(varchar,convert(datetime,vdate,103),103))),'')+'  '+ isnull(REPLACE(REPLACE(RIGHT('0'+LTRIM(RIGHT(CONVERT(varchar,convert(datetime,vtime,103),100),7)),7),'AM',' AM'),'PM',' PM'),''))
as vdate from table1


which displays vdate column in "08/04/2013 03:00 AM" format
when i sort records in asc/desc order it sorts records according to date only and not the time.I need to sort them according to both date and time.How can i do this?
Plz Help..
Posted
Updated 26-May-14 20:58pm
v2
Comments
ArunRajendra 27-May-14 3:00am    
Post your sorting query.
pwavell 27-May-14 3:18am    
add order by vdate asc/desc at the end of above query.i also tried convert(DATETIME,vrdate,103) asc/desc.Not sorting properly.

1 solution

Have you tried doing this

ORDER BY CAST([date] AS DATETIME) + CAST([time] AS DATETIME) asc
 
Share this answer
 
Comments
pwavell 27-May-14 3:46am    
ORDER BY convert(DATETIME,vdate,103) asc,convert(DATETIME,vtime,103) asc worked for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900