?
Solved

SQL Error "String or binary data would be truncated"

Posted on 2001-06-20
5
Medium Priority
?
473 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 60 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

752 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