shantanu sinha shantanu sinha - 3 months ago 7
SQL Question

how to display last 10 numbers in sql

i have a table A with two column

(number varchar(600),Date_ varchar(800))

now i have to display last 10 numbers order by Date_.

SELECT top(10) Number,Date FROM A ORDER BY Date_ DESC,


the problem is that for one month its showing result as desired,
but as soon next month start it not showing result as desired

i want the result like this.

10,2/2/2016
22,1/2/2016
10,31/1/2016
20,30/1/2016
30,29/1/2016
23,28/1/2016
20,27/1/2016
11,26/1/2016
18,25/1/2016
62,24/1/2016
56,23/1/2016
54,22/1/2016
44,21/1/2016


i am getting this result for --/1/2016 month but not for --/2/2016.
so kindly help.

Answer

Try the below script

 SELECT top(10) Number,Date 
  FROM A 
  ORDER BY convert(datetime,Date,103) DESC