Solved

SQL Error "String or binary data would be truncated"

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

Suggested Solutions

Title # Comments Views Activity
syadmin MSSQL 2 57
How to use left join to take all data from master table? 11 38
Sql query 107 22
MS SQL Pivot table help 4 0
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

937 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now