Link to home
Start Free TrialLog in
Avatar of MrLogin
MrLogin

asked on

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?
Avatar of Faiga Diegel
Faiga Diegel
Flag of United States of America image

Can you post the INSERT Statement?
Avatar of MrLogin
MrLogin

ASKER

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.
Avatar of MrLogin

ASKER

The problem column is      substring( b. SourceCol1, 22, len( b. SourceCol1))
ASKER CERTIFIED SOLUTION
Avatar of MrLogin
MrLogin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial