代码之家  ›  专栏  ›  技术社区  ›  wlfente

SQL抛出算术溢出错误

  •  3
  • wlfente  · 技术社区  · 6 年前

    所有3个查询都会引发上述相同的错误:

    Select  (SUM(ACDTalkTimeInSec) + SUM(TotAcwTimeInSec) + SUM(HoldTimeInSec)) as AHT
    From ColTelephony.dbo.vwACDSkillCombined acd
    Where WorkDte between '1/2/2018' AND '10/5/2018'
    
    Select  CAST(Cast(SUM(ACDTalkTimeInSec) AS BIGINT) + CAST(SUM(TotAcwTimeInSec) AS BIGINT) + CAST(SUM(HoldTimeInSec) AS BIGINT) AS BIGINT) as AHT
    From ColTelephony.dbo.vwACDSkillCombined acd
    Where WorkDte between '1/2/2018' AND '10/5/2018'
    
    Select  Cast(((SUM(ACDTalkTimeInSec) + SUM(TotAcwTimeInSec) + SUM(HoldTimeInSec))) AS BIGINT) as AHT
    From ColTelephony.dbo.vwACDSkillCombined acd
    Where WorkDte between '1/2/2018' AND '10/5/2018'
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Michael Bruesch    6 年前

    SMor在评论中对此进行了回答,但以下是sql:

    Select SUM(CAST(ACDTalkTimeInSec AS BIGINT)) + SUM(CAST(TotAcwTimeInSec AS BIGINT)) 
        + SUM(CAST(HoldTimeInSec AS BIGINT)) as AHT
    From ColTelephony.dbo.vwACDSkillCombined acd
    Where WorkDte between '1/2/2018' AND '10/5/2018'
    

    如果SMor公布了他们的答案,那就接受吧。我没有测试代码,所以请原谅任何错误。