Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL Insert Error - String or binary data would be truncated [duplicate]

set identity_insert tblindividual ON

insert into tblIndividual (nametitle, individ, lastname, firstname, occupation, employer, active, editor, creationdate)
   select 
       salutation, idnumber, last_name, first_name, occupation, 
       employer, 1, recstatus, GETDATE()
   from 
       i_master 
   where 
       cc_rectype = '1' 

set identity_insert tblindividual OFF

Receiving error:

Msg 8152, Level 16, State 2, Line 2
String or binary data would be truncated. The statement has been terminated.

like image 608
TrialByError Avatar asked Nov 20 '25 00:11

TrialByError


1 Answers

You're getting that error because one of the columns you are trying to insert data into is receiving data that is too large and would have to be truncated (cut short).

For example, if your nametitle field is a varchar(50) data type, but your salutation data was of type varchar(100) there could be values that will not fit without being truncated.

If you are happy to let your longer data be cut to size you can turn off the warning to allow the insert to continue using the statement:

SET ANSI_WARNINGS  OFF;
-- Your insert TSQL here.
SET ANSI_WARNINGS ON;

As above, always remember to turn warnings back on again afterwards. I hope this helps.

like image 73
Rudi Kershaw Avatar answered Nov 22 '25 15:11

Rudi Kershaw