Datepart() 函数未转换为 bigint

Datepart() function not converting into bigint

我正在尝试一个简单的 select 操作

select datepart(year,AttendanceTimeIn)*100000000  from TV_AttendanceTable

但出现以下错误:

将表达式转换为数据类型 int 时出现算术溢出错误。

我也尝试过将其类型转换为 BigInt,但没有成功,出现了同样的错误。

select CONVERT(BIGINT, datepart(year,AttendanceTimeIn)*100000000)  from TV_AttendanceTable

注意:AttendanceTimeIn 列是我 SQL table 中的日期时间类型列。

您正在 乘法后进行转换。那太晚了。您需要在 之前转换其中一个值 乘法:

CONVERT(BIGINT, datepart(year, AttendanceTimeIn)) * 100000000

或者像我这样写:

CONVERT(BIGINT, year(AttendanceTimeIn)) * 100000000