Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question
3  
Are you sure that the target table is at least as wide as the source table? What processing is happening? –  gbn May 20 '13 at 10:59
add comment

migrated from stackoverflow.com May 20 '13 at 15:39

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 5 down vote accepted

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
share|improve this answer
    
There is a trigger, but this doesn't cause the error. Updated question with more detail. –  Neil Knight May 20 '13 at 11:08
    
@NeilKnight: is your SQL that simple? and can you add the trigger code please –  gbn May 20 '13 at 11:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.