Solved

SQL Error "String or binary data would be truncated"

Posted on 2001-06-20
5
459 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

830 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