Sql-server – VarChar to NVarChar causing truncate error

sql serversql-server-2008-r2truncate

I am importing some data from a temporary table which has a column defined as VARCHAR(150). The destination tables column is defined as NVARCHAR(200). I'm using an INSERT INTO statement, but when I run the SQL statement commenting out this column the query runs correctly. When I uncomment this line, I get:

Msg 8152, Level 16, State 4, Line 26

String or binary data would be truncated.

The statement has been terminated.

Any ideas as to why this is happening?

INSERT INTO table (col1, col2)
SELECT column1
      ,column2
  FROM tmpTable

col1 is defined as NVARCHAR(200) and col2 is a DateTime.
column1 is defined as VARCHAR(150) and column2 is a DateTime.

When I comment out column1 and col1 the import statement runs fine.

Best Answer

Well this won't happen unless

  1. a trigger is firing on the target table, and the error happens there
  2. the INSERT does some processing that adds enough data to make it too wide

Also, what happens with this please? This can not fail unless there is some processing.

INSERT INTO table (col1, col2)
SELECT LEFT(column1, 200)
      ,column2
  FROM tmpTable