12

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?

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108

2 Answers2

26

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.

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
2

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
Unnikrishnan R
  • 4,965
  • 1
  • 12
  • 21