SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Msg 8152, Sev 16: String or binary data would be truncated. [SQLSTATE 22001]


Msg 8152, Sev 16: String or binary data would be truncated. [SQLSTATE 22001]

Author
Message
Roger Lin-302583
Roger Lin-302583
SSC Rookie
SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)SSC Rookie (26 reputation)

Group: General Forum Members
Points: 26 Visits: 37
If you don't care the data to be truncated, just turn the ANSI_WARINGS OFF, the data will be truncated to fit the row and no error no fuss everything will work fine. Here is what you can see the effect:

CREATE TABLE #tst (t char(2))
insert #tst values ('abc')

Execute that you get the following error:
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Then run this:
set ansi_warnings off
insert #tst values ('abc')

You will get this:
(1 row(s) affected)
peter.roothans
peter.roothans
SSC Journeyman
SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)SSC Journeyman (81 reputation)

Group: General Forum Members
Points: 81 Visits: 157
Hi,

I just had the same issue and it was caused by a trigger that stores all updates in an audit table. The audit table stores some additional information as SUSER_SNAME and APP_NAME ...

After adding substring function the problem was solved
SUBSTRING(APP_NAME(), 1, 50)

APP_NAME() in ssms is about 47 characters but when you execute via a job it returns SQL AGENT .... + a guid ... which is longer than 50 chars.

Kind regards
Peter.
bobaer
bobaer
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 170
Stuart Mark Housden (9/8/2008)
I had this same problem where I always get the "truncation" message when executing stored procedures in SQL Server Agent jobs but never getting the message when I run it in Management Studio.

After trying a number of desperate measures I commented out some "Print" statements I had and the error messages went away.


This was my problem. Thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search