Solved

SQL Error "String or binary data would be truncated"

Posted on 2001-06-20
5
463 Views
Last Modified: 2008-03-10
I was inserting some stuff into a database today and got the following error "String or binary data would be truncated."  I hadn't seen it before.  I looked at my code and coudln't find anything wrong.  I then retried the INSERT with the EXACT same data, and it worked fine.  Have any idea what the error is or where it comes from?
0
Comment
Question by:NJordan72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:daniel_c
ID: 6212466
Yupe, the length of the data you insert (usually string) exceeds the length of the field.

For example:
tabel: PRODUCT
field: productname varchar(10)


You do this:
INSERT INTO Product('1234567890123')

It will raise the error.
0
 
LVL 18

Expert Comment

by:nigelrivett
ID: 6212588
If you tried the insert with the same data then it implies that it it is not just the values that are too long.

How were you doing the insert that fails.
I suspect your test was via query analyser and there is something in the interface that failed previously.
0
 

Author Comment

by:NJordan72
ID: 6214110
I was doing the insert via an Activer Server Page.
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6214307
Okay, post your ASP code, then let's see it.
0
 
LVL 3

Accepted Solution

by:
ibro earned 15 total points
ID: 6216082
error "String or binary data
would be truncated."  is showed only if the SET ANSI_WARNINGS is ON. If you tried to insert the same data in the table with ANSI_WARNINGS set OFF it will not raise any error and it will automaticly truncate your data to max size of the field.
Probably you got the error in enviroment with set ANSI_WARNINGS ON, and normaly it is set OFF.
Check your ODBC settings if your application uses ODBC, or if you use Query Analizer, just type:
SET ANSI_WARNINGS OFF
  hope this will help!
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question