SQL Server 将 Smalldatetime 与日期时间字符串进行比较

Dan*_*ngs 1 sql-server date

我似乎找不到任何示例,其中人们使用 smalldatetime 类型来查询日期以外的任何内容。我可以使用日期查询,但它忽略了时间。我在表中有一行日期为“ 24/06/2016 12:10:00”。我想查询此表以提取日期和时间小于当前时间的所有行。问题是它完全忽略了时间,只与日期匹配。使用以下 where 子句,我不希望有任何结果,因为表中的行是 12:10。

WHERE startdate < '2016-06-24 12:00:00'
Run Code Online (Sandbox Code Playgroud)

我如何格式化查询,以便服务器在返回结果时将时间影响。

Mil*_*ney 5

问题一定是其他问题,因为我使用 smalldatetime 的 where 子句确实考虑了时间组件......

WITH TestData as (
SELECT
    cast('2016-24-06 11:50:00' as smalldatetime) as TheDate
UNION ALL
SELECT
    cast('2016-24-06 12:10:00' as smalldatetime) as TheDate
)
select * from TestData
WHERE TheDate < cast('2016-24-06 12:00:00' as smalldatetime)
Run Code Online (Sandbox Code Playgroud)

也许将 Where 子句中的日期显式转换为 smalldatetime?