DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to sort on date column?

If a date column in char/varchar MM/DD/YY format, it will not sort correctly in an order by clause.

It is better to use the 111, 112 string date formats to define the date column as YYYY/MM/DD or YYYY.MM.DD :

select convert(char(10), getdate(),112)

-- Sort MM/DD/YY similar string date format

ORDER BY convert(datetime, YourDate,1)

 

-- or in SQL Server 2008

 

ORDER BY convert(date, YourDate,1)

 

More on datetime / date conversion at the following link:


http://www.sqlusa.com/bestpractices/datetimeconversion/

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE