【问题标题】:Int to numeric conversion error in SQL ServerSQL Server 中的 Int 到数值转换错误
【发布时间】:2013-05-17 06:47:04
【问题描述】:

我对转换数据有疑问。我有一个在 VBA 中进行的选择查询,如何将 varchar 值列转换为 nvarchar

我得到这个错误:

将数字转换为数据类型数字的算术溢出错误

这是我的代码:

Dim strSQL As String
 Dim rst As New ADODB.Recordset

 strSQL = " INSERT INTO dbo.Soferi_test (test1)" & _
       " SELECT MySQL.dbo.sofieri.certificat_cipti " & _
       " FROM  MySQL.dbo.sofieri " & _
       " WHERE IDNO = " & Forms!Forma_redactare_soferi!IDNO.Value

 Call AttServ(strSQL, rst) 

【问题讨论】:

    标签: sql sql-server ms-access vba


    【解决方案1】:

    您的 int 值对于数值精度和比例定义来说太大了

    在这里,我猜错误来自 WHERE 子句。不是插入

    DECLARE @foo int = 99999;
    DECLARE @n1 numeric(9,1), @n2 numeric (3,2);
    
    -- 9,1 is 9 total digits, 1 decimal place
    -- 3,2 is 2 total digits, 2 decimal places
    
    -- 99999 requires at least 5 total digits
    
    PRINT 'Wide enough'
    SET @n1 = @foo;
    
    
    PRINT 'Error'
    SET @n2 = @foo;
    

    评论后还是一样

    DECLARE @foo numeric(5,0) = 99999;
    DECLARE @n1 numeric(9,1), @n2 numeric (3,2);
    
    PRINT 'Wide enough'
    SET @n1 = @foo;
    
    
    PRINT 'Error'
    SET @n2 = @foo;
    

    【讨论】:

    • 抱歉,在我的错误不是 INT 中,我把它的数字误认为数据类型 numeric
    • @Sergio:同样适用。
    • 如何在 vba 中更新此语句?我是 Vba 和 sql 中的新人
    • 您必须确保 WHERE 子句中的数据类型在 VBA 和 SQL 之间匹配
    猜你喜欢
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    相关资源
    最近更新 更多