views:

66

answers:

1
tblCurrent_locations
Id   BusNo        Date              Time 
1   mh30q121     2009/12/18       11:00:00 
2   mh30q121     2009/12/18       1245:30
3   mh30q121     2009/12/18       11:30:00
4   mh30q121     2009/12/18       1015:00
5   mh30q121     2009/12/18       11:00:00 
6   mh30q121     2009/12/19      13:00:00
7   mh30q121     2009/12/19       13:15:30
8   mh30q121     2009/12/19       14 15 39
9   mh30q121     2009/12/19       12:30:00
10   mh30q121     2009/12/20       14:00:30
11   mh30q121     2009/12/20       14:08:00
12   mh30q121     2009/12/20       14:02:30
13  mh30q121     2009/12/20       14:4:00
14  mh30q121     2009/12/20       14:04:30
15  mh30q121     2009/12/20       14:07:00
16  mh30q121     2009/12/20       14:07:30

Here I want to retrieve last n records sorted by date and time.

+3  A: 
SELECT TOP n * FROM tblCurrent_locations ORDER BY "Date" DESC, "Time" DESC

EDIT

As gbn noticed

SELECT TOP n * FROM tblCurrent_locations ORDER BY [Date] DESC, [Time] DESC

doesn't rely on other settings.

LukLed
Minor quibble: ORDER BY [Date] DESC, [Time] DESC
gbn
@gbn: I prefer "Date". It is universal and works on other engines too.
LukLed
Treum, but it relies on SET QUOTED_IDENTIFIER ON
gbn