【问题标题】:Stored Procedure Arithmetic overflow error converting expression to data type int将表达式转换为数据类型 int 的存储过程算术溢出错误
【发布时间】:2015-10-15 06:16:04
【问题描述】:

我正在尝试使用以下存储过程,但出现错误

消息 8115,级别 16,状态 2,过程 xlaAFSsp_reports,第 25 行
将表达式转换为数据类型 int 时出现算术溢出错误。

第 24 行:将 myadapter 调暗为新的 SqlDataAdapter(mycommand)
第 25 行:mycommand.CommandType = CommandType.StoredProcedure
第 26 行:myadapter.fill(ds,"results")
第 27 行:
第 28 行:rs=ds.tables(0).rows(0)

表中的值不为 0

知道是什么原因造成的吗?

ALTER PROCEDURE [dbo].[xlaAFSsp_reports]
AS
    SET NOCOUNT ON

    -- Consolidate disk size (also done on xlaAFSsp_expire_files)
    UPDATE xlaAFSstorages 
    SET currentsize = ISNULL((select SUM(filesize) 
                              from xlaAFSfiles 
                              where s3 = 0 
                                and storageid = xlaAFSstorages.storageid), 0)

    create table #ttable (
       totalfiles int,
       usedspace int,
       nonexpiring int,
       protected int,
       totalusers int,
       paidusers int,
       totalstorages int,
       allocatedspace int,
    )

    -- Total Stats
    insert into #ttable (totalfiles, usedspace, nonexpiring, protected, totalusers, paidusers, totalstorages, allocatedspace) 
    values (0, 0, 0, 0, 0, 0, 0, 0)

    update #ttable 
    set totalfiles = (Select count(fileid) from xlaAFSfiles), 
        usedspace = (Select isnull(sum(filesize), 0) from xlaAFSfiles), 
        nonexpiring = (Select count(fileid) from xlaAFSfiles 
                       where fsid in (select fsid from xlaAFSfilesets 
                                      where expiredate = '-')), 
        protected = (Select count(fileid) from xlaAFSfiles 
                     where fsid in (select fsid from xlaAFSfilesets 
                                    where accesspwd <> '')),
        totalusers = (Select COUNT(userid) from xlaAFSusers),
        paidusers = (Select COUNT(userid) from xlaAFSusers where ispaid <> ''),  
        totalstorages = (Select COUNT(storageid) from xlaAFSstorages),
        allocatedspace = (Select isnull(SUM(allocatedsize),-1) 
                          from xlaAFSstorages)


      select * from #ttable
      drop table #ttable

【问题讨论】:

    标签: sql sql-server stored-procedures


    【解决方案1】:

    听起来其中一个总和大于 2,147,483,647。

    MS-SQL int, bigint, smallint, and tinyint

    【讨论】:

    • 和/或 xlaAFSstorages 中的字段之一不是 INT(可能是 NUMERIC、FLOAT 甚至 heaven forbid VARCHAR),并且隐式强制导致了问题。
    • 该列是一个浮点数,但说我不能在不删除表格的情况下更改它
    • 提出了为什么文件大小会存储为浮点数的问题...但是您可以更改临时表中的数据类型以匹配吗?
    • 如果你不能改变底层数据,改变你使用它的方式。让所有你的字段浮动?一旦你让它发挥作用,你就可以挑战设计假设。
    • 执行以下操作,仍然相同的错误 totalfiles float, usedspace float, nonexpiring float, protected float, totalusers float,paidusers float, totalstorages float, allowedspace float,
    猜你喜欢
    • 2011-10-07
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多