从SQL表中选择MAX TIMESTAMP作为BIGINT

时间:2015-09-28 09:13:31

标签: sql-server timestamp max bigint

我担心以下查询的表现:

SELECT 
    MAX(CAST((CONVERT(bigint, DBTimeStamp)) AS decimal)) AS DBTimeStamp 
FROM Category 
WHERE DepartmentID = 5

是否有更快的方法可以从表中获取最大/最新时间戳作为整数?

1 个答案:

答案 0 :(得分:0)

如果计算转换和转换的最大值,则SQL可以使用索引,只需要转换和转换一次:

SELECT 
CAST(CONVERT(bigint,MAX( DBTimeStamp)) AS decimal) AS DBTimeStamp 
FROM Category 
WHERE DepartmentID = 5