2013-05-17 39 views
0

我有转换数据的问题。我在VBA做了一个选择查询,我如何从varchar值列转换为nvarchar诠释到数字转换误差在SQL Server

我得到这个错误:

Arithmetic overflow error converting numeric to data type numeric

这是我的代码:

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) 

回答

1

你的int值过大的数值精度和规模定义

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

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; 
+0

对不起,我错了其数字数据类型数字在我的错误不是int – Sergio

+0

@Sergio:同样适用。 – gbn

+0

我如何更新vba中的这些声明?我是在VBA和SQL – Sergio

相关问题