【问题标题】:Datepart() function not converting into bigintDatepart() 函数未转换为 bigint
【发布时间】:2021-08-06 15:26:24
【问题描述】:

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

select datepart(year,AttendanceTimeIn)*100000000  from TV_AttendanceTable

但出现以下错误:

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

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

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

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

【问题讨论】:

  • 您使用的是哪个 dbms? (datetimedatepartconvert 都是产品特定的功能。)

标签: sql datetime type-conversion integer bigint


【解决方案1】:

你在乘法之后转换。那为时已晚。您需要在乘法之前转换其中一个值

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

或者就像我写的那样:

CONVERT(BIGINT, year(AttendanceTimeIn)) * 100000000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2021-06-23
    • 2012-04-11
    • 2012-07-20
    相关资源
    最近更新 更多