SQL Server中的Int到数字转换错误

时间:2013-05-17 06:47:05

标签: sql sql-server vba access-vba

我对转换数据有疑问。我在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) 

1 个答案:

答案 0 :(得分: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;