Order By Datetime in SQL Server not ordering Properly -
i trying order dataset datetime in sql server. using dd/mm/yyyy
format. can assume following query simplicity.
select convert(nvarchar(50), datecolumn, 103) mytable order datecolumn desc;
but returns records sorted dd , ignores mm,yy.
you can have on following data.
29/07/2015 26/09/2015 25/09/2015 25/09/2015 24/07/2015 22/09/2015 12/06/2015 01/10/2015
what should may include mm , yy
while ordering.
my guess actual query is:
select convert(nvarchar(50), datecolumn, 103) datecolumn -------------------------------------------------^ note alias here same used in order mytable order datecolumn desc;
the order by
uses column definition in select. can change name. alternatively, use qualified column name in order by
:
select convert(nvarchar(50), t.datecolumn, 103) datecolumn mytable t order t.datecolumn desc;
Comments
Post a Comment