我需要选择过去15分钟内更改的记录,这会有效吗?
--Select changed records
USE PC
SELECT
PEOPLE_CODE, PEOPLE_ID, PEOPLE_CODE_ID, PREVIOUS_ID,
FIRST_NAME, MIDDLE_NAME, LAST_NAME, REVISION_DATE, REVISION_TIME
FROM
PEOPLE
WHERE
REVISION_DATE >= getdate()
--Also need to check for time
AND REVISION_TIME >= dateadd(minute,-15,getdate()) --Test record
ORDER BY
REVISION_DATE DESC, REVISION_TIME DESC
答案 0 :(得分:0)
我认为你就在那里,只需要组合日期和时间列值。您可以使用隐式或显式方法。隐含的优点是它快速且易于编写。显式选项的优点是,如果REVISION_DATE
列的时间部分填充了00:00:00.000
之外的其他内容,或者REVISION_TIME
的日期部分填充了除1900-01-01
以外的其他内容USE PC
SELECT
PEOPLE_CODE, PEOPLE_ID, PEOPLE_CODE_ID, PREVIOUS_ID,
FIRST_NAME, MIDDLE_NAME, LAST_NAME, REVISION_DATE, REVISION_TIME
FROM
PEOPLE
WHERE
(REVISION_DATE + REVISION_TIME) >= dateadd(minute,-15,getdate())
ORDER BY
REVISION_DATE DESC, REVISION_TIME DESC
,它仍然会按预期工作。
<强>隐式:强>
USE PC
SELECT
PEOPLE_CODE, PEOPLE_ID, PEOPLE_CODE_ID, PREVIOUS_ID,
FIRST_NAME, MIDDLE_NAME, LAST_NAME, REVISION_DATE, REVISION_TIME
FROM
PEOPLE
WHERE
(dateadd(d, datediff(d, 0, REVISION_DATE), 0) + dateadd(d, -datediff(d, 0, REVISION_TIME), REVISION_TIME)) >= dateadd(minute,-15,getdate())
ORDER BY
REVISION_DATE DESC, REVISION_TIME DESC
<强>显强>
libc++abi.dylib: terminating with uncaught exception of type NSException