gpt4 book ai didi

SQL Server : Arithmetic overflow error converting expression to data type int

转载 作者:行者123 更新时间:2023-12-01 18:34:30 25 4
gpt4 key购买 nike

我收到此错误

msg 8115, level 16, state 2, line 18
Arithmetic overflow error converting expression to data type int.

使用此 SQL 查询

DECLARE @year VARCHAR(4);                       
DECLARE @month VARCHAR(2);

-- START OF CONFIGURATION SECTION
-- THIS IS THE ONLY SECTION THAT SHOULD BE MODIFIED
-- SET THE YEAR AND MONTH PARAMETERS

SET @year = '2013';
SET @month = '3'; -- 1 = January.... 12 = Decemeber.

-- END OF CONFIGURATION SECTION

DECLARE @startDate DATE
DECLARE @endDate DATE
SET @startDate = @year + '-' + @month + '-01 00:00:00';
SET @endDate = DATEADD(MONTH, 1, @startDate);

SELECT
DATEPART(YEAR, dateTimeStamp) AS [Year]
, DATEPART(MONTH, dateTimeStamp) AS [Month]
, COUNT(*) AS NumStreams
, [platform] AS [Platform]
, deliverableName AS [Deliverable Name]
, SUM(billableDuration) AS NumSecondsDelivered
FROM
DeliveryTransactions
WHERE
dateTimeStamp >= @startDate
AND dateTimeStamp < @endDate
GROUP BY
DATEPART(YEAR, dateTimeStamp)
, DATEPART(MONTH, dateTimeStamp)
, [platform]
, deliverableName
ORDER BY
[platform]
, DATEPART(YEAR, dateTimeStamp)
, DATEPART(MONTH, dateTimeStamp)
, deliverableName

最佳答案

问题出在SUM(bilableDuration)上吗?要找出答案,请尝试注释掉该行并查看它是否有效。

总和可能超过int最大值。如果是这样,请尝试将其替换为 SUM(CAST(bilableDuration AS BIGINT))

关于SQL Server : Arithmetic overflow error converting expression to data type int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15950580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com