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).
Then Insert multiple rows...
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....
Screen Shot bellow....
Then I try sort inserted rows in date wise with dessending order.
but does not sorting properly....
I want to sort.... assending/desending order that is (assending order):
| Roll | StuName | AdmissionDate |
| 15 | Shyam Das | 09-Apr-2014 |
| 12 | Madhu das | 02-May-2014 |
| 18 | Jadu Das | 05-May-2014 |
| 20 | Rabin Das | 10-May-2014 |
| 10 | Ram Das | 10-May-2014 |
| 14 | Rabi Das | 22-Jun-2014 |
Please Help me.
Satyapriya NayakPosted Jun 6, 2014, 12:04 PM
*
FROM StuInfo
ORDER BY CAST(AdmissionDate AS DATETIME)
Ravi PrakashPosted Jun 5, 2014, 9:09 AM
This is Ravi Prakash
Your Question is you cant sort data by data Column
Your table structure is
create table stuinfo(
Roll int ,name nvarchar(50), date nvarchar(50)
)
When u execute query
select * from stuinfo order by desc
then query is execute according to data column but u column is nvarchar(50)
create table stuinfo(
Roll int ,name nvarchar(50), date datetime
)
the date part should be datetime
Khan Abrar AhmedPosted Jun 5, 2014, 9:05 AM
cast (AdmissionDate as date)
or convert(varchar,AdmissionDate,106)
Anupam SinghPosted Jun 5, 2014, 9:02 AM
Because you are using varchar type for dates, it will not apply shorting as expected.
you should alter table and change this to DateTime. However you can use CONVERT function but I dont think will work with this format.