Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
=======================================================================Invalid sorting date column in .net-------------------------------------------------------Hi i am using MS SQL Server 2000 on back end and on front end i am using ASP.NET to show the data while accessing data from table i want to sort date in descending order but it shows below invalid order.4/10/20084/10/20084/10/20084/15/20084/15/20084/9/20084/9/20084/9/20089/10/2007the exact order is 4/9/20084/9/20084/9/20084/10/20084/10/20084/10/20084/15/20084/15/20089/10/2007which is not coming in front so if any one have idea plz guide meRegards.Ali.webmaster http://www.GlobalGuideLine.com
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2008-06-11 : 03:50:52
The sorting is correct. According to string sorting.Replace your query in the database asselect Col1 from table1 order by convert(datetime, col1, 101)E 12°55'05.25"N 56°04'39.16"
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-06-11 : 03:51:38
Are you specifying explicitly the order required using ORDER BY clause? Also is you date field having datatype of datetime?
johnsql
Posting Yak Master
161 Posts
Posted - 2008-06-11 : 14:17:38
declare @t table(dt datetime)insert @tselect '4/10/2008'union all select '4/10/2008'union all select '4/10/2008'union all select '4/15/2008'union all select '4/15/2008'union all select '4/9/2008'union all select '4/9/2008'union all select '4/9/2008'union all select '9/10/2007'--select * from @torder by year(dt) desc, day(dt), month(dt)
jsmith8858
Dr. Cross Join
7423 Posts
Posted - 2008-06-11 : 15:57:13
johnsql -- why would you do it that way? That is completely unnecessary and inefficient. Simply ORDER BY the datetime column. that's it.The problem the original poster is having is a simple one: He is not using correct data types, whether it is how he is storing his dates, or how he is returning them in a SELECT, or how he has his DataColumn declared.see: http://weblogs.sqlteam.com/jeffs/archive/2007/07/03/60248.aspx- Jeffhttp://weblogs.sqlteam.com/JeffS