How to Sorting rows in date wise in sql server 2005?

Posted by prakashmondal5-21103 under Sql Server on 6/5/2014 | Points: 10 | Views : 4946 | Status : [Member] | Replies : 1
I want to sort multiple rows in date wise in sql server 2005..

First I create a table "StuInfo" and two attributes StuName, AdmissionDate their datatype are varchar2(20).

create database ForTest;
create table StuInfo(Roll int, StuName varchar(50), AdmissionDate varchar(20));
insert into StuInfo values(10,'Ram Das','10-May-2014');
insert into StuInfo values(15,'Shyam Das','09-Apr-2014');
insert into StuInfo values(18,'Jadu Das','05-May-2014');
insert into StuInfo values(12,'Madhu Das','02-May-2014');
insert into StuInfo values(14,'Rabi Das','22-Jun-2014');
insert into StuInfo values(20,'Rabin Das','10-May-2014');


After Insert I try to sort inserted rows in date wise with assending order.

command is:

select *from StuInfo order by AdmissionDate desc;

but does not sorting properly....

I want to sort.... assending/desending order that is (assending order):

AdmissionDate

09-Apr-2014
02-May-2014
05-May-2014
10-May-2014
10-May-2014
22-Jun-2014

Please Help me.




Responses

Posted by: Satyapriyanayak on: 6/6/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
SELECT
AdmissionDate
FROM StuInfo
ORDER BY CAST(AdmissionDate AS DATETIME)


-----------------------------------------------

SELECT CONVERT(DATETIME, AdmissionDate, 103)
FROM StuInfo
ORDER BY CONVERT(DATETIME, AdmissionDate, 103)

If this post helps you mark it as answer
Thanks

prakashmondal5-21103, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response