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?

10
  • And the question is? Commented Aug 29, 2016 at 7:22
  • Updated. If you can, please undo the downvote since I already update it. Thanks Commented Aug 29, 2016 at 7:24
  • I didn't downvote, so I can't undo it. Commented Aug 29, 2016 at 7:25
  • 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. Commented Aug 29, 2016 at 7:26
  • 1
    Possible duplicate of SQLException : String or binary data would be truncated Commented Aug 29, 2016 at 7:35

2 Answers 2

27

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've quoted the essence. I just refer the link to honor the original author
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

Comments

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.