K
Kjell Arne Johansen
Hi
In a table a have a datetime field called ’Time’ and I query records before
or after a specific time.
Example, three records with the following values in the 'Time' field
‘22-02-2008 10:23:31’
‘22-02-2008 10:23:32’
‘22-02-2008 10:23:33’
This simple query (GetPrevious)
SELECT TOP 1 *
FROM events
WHERE
[time] < #22-02-2008 10:23:32#
ORDER BY
[time] DESC
gives the record with 'Time' field:
‘22-02-2008 10:23:31’
as excepted.
This query (GetNext)
SELECT *
FROM (
SELECT TOP 1 *
FROM events
WHERE
[time] > #22-02-2008 10:23:32#
ORDER BY
[time] ASC
) AS Next
ORDER BY
[time] DESC
gives the record with 'Time' field:
‘22-02-2008 10:23:32’
which I do not expect. I hoped for ‘22-02-2008 10:23:33’.
Why do I get ‘22-02-2008 10:23:32’ and not ‘22-02-2008 10:23:33’?
I’m a little confused.
Help will make me very happy
Regards
Kjell Arne Johansen
In a table a have a datetime field called ’Time’ and I query records before
or after a specific time.
Example, three records with the following values in the 'Time' field
‘22-02-2008 10:23:31’
‘22-02-2008 10:23:32’
‘22-02-2008 10:23:33’
This simple query (GetPrevious)
SELECT TOP 1 *
FROM events
WHERE
[time] < #22-02-2008 10:23:32#
ORDER BY
[time] DESC
gives the record with 'Time' field:
‘22-02-2008 10:23:31’
as excepted.
This query (GetNext)
SELECT *
FROM (
SELECT TOP 1 *
FROM events
WHERE
[time] > #22-02-2008 10:23:32#
ORDER BY
[time] ASC
) AS Next
ORDER BY
[time] DESC
gives the record with 'Time' field:
‘22-02-2008 10:23:32’
which I do not expect. I hoped for ‘22-02-2008 10:23:33’.
Why do I get ‘22-02-2008 10:23:32’ and not ‘22-02-2008 10:23:33’?
I’m a little confused.
Help will make me very happy
Regards
Kjell Arne Johansen