T-SQL truncation error on SQL Server 2005 - bug?

Hi everyone,

In migrating from SQL 2000 to 2005 (64 bit) we have come across an insert statement that no longer works.   We have been able to get the original insertion statement to work by leaving one column out and processing it afterwards.  

1. If the (previously ok) problem column is included the insert statement returns "String or binary data would be truncated".
2. If the column is processed on its own the insert statement works correctly.
3. If the column is excluded the insert statement works correctly.
As a work around we use approach (3) and update the table with the missing column - the update works without any problem.

The target table problem column is varchar(100).   The corresponding source column is varchar(500).   None of the entries in the source column is wider than about 50 characters.

The target table has no keys, constraints, triggers or indexes defined.   ANSI settings appear to be the same in 2000 and 2005.

Anyone come across this and any known work arounds?
Who is Participating?
MrLoginConnect With a Mentor Author Commented:
As there is no material response here and a work around is in place to this apparent 64 bit MS SQL server TSQL failure closing the question.
Faiga DiegelSr Database EngineerCommented:
Can you post the INSERT Statement?
MrLoginAuthor Commented:
Insert into Target_Table
      (Col1, Col2, ID , Name, Amount1, Amount2, Col8)
select 'XXX', a.Sourcecol1, convert(int,substring( b.SourceCol1, 17, 4)),
            substring( b. SourceCol1, 22, len( b. SourceCol1)),
            (a.Amt11 + a.Amt12 + a.Amt13 + a.Amt14),
            (a.Amt21 + a.Amt22 + a.Amt23 + a.Amt24, Ltrim(a.SouceCol2)
      from Source_Table1 a, Source_Table2 b
      where left( a. Sourcecol1, 4) = substring( b. SourceCol1, 17, 4)

Of interest we also changed the width of the problem target column to varchar(500) - so it matched the width of the source column exactly and still got the same error.
MrLoginAuthor Commented:
The problem column is      substring( b. SourceCol1, 22, len( b. SourceCol1))
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.