0

I have a question with converting data. I have a select query made in VBA, how can I convert from varchar value column to nvarchar.

I get this error:

Arithmetic overflow error converting numeric to data type numeric

This is my code:

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 Answer 1

1

Your int value is too big for the numeric precision and scale definition

Here, I guess the error comes from the WHERE clause. Not the 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;

After comment, the same still applies

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;
Sign up to request clarification or add additional context in comments.

4 Comments

sorry i had mistake its numeric to data type numeric in my error not INT
@Sergio: the same applies.
how can i update this statments in vba? i am new one in Vba and in sql
You will have to ensure the datatypes in the WHERE clause match between VBA and SQL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.