从 [最新数据日期] 和 [现在] 之间的位置插入 Select

Insert Into Select From Where Between [Latest Data's Date] And [Now]

我正在尝试 运行 下面显示的查询,以便将所有数据从 RemoteServer 复制到 LocalServer,这是在最新时间戳记录的日期和我执行查询。

INSERT INTO [LocalServer].[database1].[dbo].[Table1]
SELECT * FROM [RemoteServer].[database1].[dbo].[Table1]
WHERE TimeCol BETWEEN MAX(TimeCol) and CURRENT_TIMESTAMP

但是,运行此查询会导致以下错误:

Msg 147, Level 15, State 1, Line 3 An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.

这条错误消息在说什么?我正在寻找什么查询来完成我想要的?

您不能在 WHERE 中使用 MAX(),因为它是一个聚合函数。请改用 HAVING()。这是你想要的吗?

INSERT INTO [LocalServer].[database1].[dbo].[Table1]
SELECT * FROM [RemoteServer].[database1].[dbo].[Table1]
WHERE TimeCol BETWEEN (SELECT MAX(TimeCol) FROM 
[LocalServer].[database1].[dbo].[Table1]) and CURRENT_TIMESTAMP

根据 Martin Smith 的评论编辑