Solved

How to set primary keys in descending date order?

Posted on 2004-09-10
3
895 Views
Last Modified: 2012-06-22
Here is a table I am working with:

dates         char           20
filename    text            16

It basically logs date and filename a user uploads. However the "dates" field was originally set as Char type. If I do set the primary key as descending order, it sorts like this:

9/3/2004
9/2/2004
9/1/2004
9/11/2004
9/12/2004
...etc

which is not the correct date order. The correct date order should be:

9/12/2004
9/11/2004
9/3/2004
9/2/2004
9/1/2004

It didn't seem I can change the Char type to Datetime type. In this case, how can I sort the primary keys in descending date order??  Thank you very much!!

0
Comment
Question by:iLvChopin
[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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Jay Toops earned 125 total points
ID: 12030456
select dates from mytable
order by cast(dates as datetime)
0
 
LVL 10

Expert Comment

by:Jay Toops
ID: 12030470
sorry forgot descending

select dates from mytable
order by cast(dates as datetime)  desc

Jay
0
 

Author Comment

by:iLvChopin
ID: 12030828
this is an easy one. :-) Thank you!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

717 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