Question : Where or between  on row_number

I need to  show some_content_field/s on a table , the range of the record i need to show is,
(N) record revers (when order by date) from the last record that mach the given date.

for this example
given date='2009-12-13 04:00'
N=4

"THE ROW_NUMBER FIELD DO NOT EXIST ON THE TABLE"

ID    DATE&TIME             row_number      some_content_field
50    2009-12-13 01:00       1                  XXXXXXXXXXXXXXXX
51    2009-12-13 01:00       2                  XXXXXXXXXXXXXXXX
52    2009-12-13 01:00       3                  XXXXXXXXXXXXXXXX
53    2009-12-13 04:00       4                  XXXXXXXXXXXXXXXX
54    2009-12-13 04:00       5                  XXXXXXXXXXXXXXXX
55    2009-12-13 04:00       6                  XXXXXXXXXXXXXXXX  

the result should be the row between 6-3   "WITHOUT THE ROW_NUMBR FIELD"

52    2009-12-13 01:00       3                  XXXXXXXXXXXXXXXX
53    2009-12-13 04:00       4                  XXXXXXXXXXXXXXXX
54    2009-12-13 04:00       5                  XXXXXXXXXXXXXXXX
55    2009-12-13 04:00       6                  XXXXXXXXXXXXXXXX

I try to do between on row_number function  it didn't work

Answer : Where or between  on row_number

The last note:

If the DATE&TIME is the real column name then it has to be enclosed into square brackets in all SQL statements:
1:
2:
3:
4:
5:
6:
7:
8:
DECLARE @n int, @givenDate smalldatetime  
SET @n = 4   
SET @givenDate = '2009-12-13 04:00'  
   
SELECT ID, [date&time], some_content_field    
  FROM ( SELECT TOP (@n) * FROM YourTable WHERE [date&time] <= @givenDate  
 ORDER BY [date&time] desc, ID desc) lastN   
 ORDER BY [date&time], ID
Random Solutions  
 
programming4us programming4us