-1

I am getting false error message while data inserting to some table.

The data type for the field is Varchar(20) and the data being inserted has max data length is 6.

I don't understand where's the issue is. Although I can avoid this by adding

SET ANSI_WARNINGS OFF

But it'd be workaround not a solution:

Details

Mr. K
  • 380
  • 3
  • 15
  • sh.Name is probably nVARCHAR? – Mike Miller Sep 06 '16 at 10:19
  • Possible duplicate of [error, string or binary data would be truncated when trying to insert](http://stackoverflow.com/questions/5591473/error-string-or-binary-data-would-be-truncated-when-trying-to-insert) – Matthias Burger Sep 06 '16 at 10:19
  • @MatthiasBurger If you don't understand the problem then atleast don't comment. Anyone can say that "field length is smaller than the insert value". – Mr. K Sep 06 '16 at 10:24
  • 1
    `sh.name` is type of `sysname` - basically `nvarchar(128)` while your schemaname-type is `varchar`. So that's the problem. – Matthias Burger Sep 06 '16 at 10:32

4 Answers4

1

It seems your column SchemaName maxlength property smaller then value which you going to insert.

Update your column length as per your data.

ALTER TABLE Temp ALTER COLUMN SchemaName VARCHAR(XXXX)
1

I just found the root cause of this issue. Actually I was trying to insert sysname data type value into varchar(). So must specify proper length to hold sysname data type.

Mr. K
  • 380
  • 3
  • 15
0

Your target table is not sufficient to hold the data that you are trying to insert. It seems your target size would be varchar(256) but you have given varchar(10). Just extend the column size to resolve this issue.

Run this DDL

Alter table temp alter column SchemaName varchar(256)
StackUser
  • 5,370
  • 2
  • 24
  • 44
  • I don't understand when the data length already mentioned is 12 so what's the point using 'varchar(256)' – Mr. K Sep 06 '16 at 10:16
0

This error come when your column has less size them. Update size of your column.

Mohit Dagar
  • 522
  • 6
  • 21