8
votes

I got this error when inserting data to Microsoft SQL.

error: ('22001', '[22001] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]String or binary data would be truncated. (8152) (SQLParamData); [01000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The statement has been terminated. (3621)')

FYI, I use Python 2.7 and pyodbc library.

What is that error about? What should I do to solve it?

2
And the question is? - jarlh
Updated. If you can, please undo the downvote since I already update it. Thanks - Aminah Nuraini
I didn't downvote, so I can't undo it. - jarlh
The error message says it all, you try to copy data too big to fit the target, so the data gets truncated. Now you have to find the failing assignment, and adjust it somehow. - jarlh

2 Answers

22
votes

Based on this link: http://www.sql-server-performance.com/2007/string-or-binary-data-truncated/

This error message appears when you try to insert a string with more characters than the column can maximal accommodate.

2
votes

figure out the issue using following step. in your insert satement ,use 'LEN' function to find the length of the input columns.

suppose you are selecting data from a temp table for input. use the below query to find out maximum size of that column and compare with the actual size of the column in your original table (table you are going to insert data).

    SELECT MAX(LEN(column1))
    FROM #yourInputData