For this answer, which handles more complex selection queries well enough, suppose we have three tables defined as follows:
CREATE TABLE [dbo].[Authors]( [AuthorID] [int] NOT NULL, [AuthorName] [varchar](20) NOT NULL ) ON [PRIMARY] CREATE TABLE [dbo].[Books]( [BookID] [int] NOT NULL, [AuthorID] [int] NOT NULL, [BookName] [varchar](20) NOT NULL ) ON [PRIMARY] CREATE TABLE [dbo].[Publications]( [BookID] [int] NOT NULL, [PublicationName] [varchar](10) NOT NULL, [AuthorID] [int] NOT NULL, [WrittenBy] [varchar](10) NOT NULL ) ON [PRIMARY]
... and we create the following data ...
INSERT INTO Authors ( AuthorID, AuthorName ) VALUES ( 1, 'BOB' ) INSERT INTO Authors ( AuthorID, AuthorName ) VALUES ( 2, 'JANE' ) INSERT INTO Authors ( AuthorID, AuthorName ) VALUES ( 3, 'SOREN LONGNAMESSON' ) INSERT INTO Books ( BookID, AuthorID, BookName ) VALUES ( 1, 1, 'My Life' ) INSERT INTO Books ( BookID, AuthorID, BookName ) VALUES ( 2, 2, 'Writing Long Titles For Dummies' ) INSERT INTO Books ( BookID, AuthorID, BookName ) VALUES ( 3, 3, 'Read Me' )
... and our complex query that throws an error ...
INSERT INTO Publications SELECT Books.BookID, Books.BookName, Authors.AuthorID, Authors.AuthorName FROM Books JOIN Authors ON Books.AuthorID = Authors.AuthorID
... then we can find columns that can be offensive like this ...
Step 1 Convert the INSERT statement to a SELECT INTO statement and write the results to a temporary table like this ...
SELECT Books.BookID, Books.BookName, Authors.AuthorID, Authors.AuthorName INTO
Step 2 Now run the following T-SQL to compare the definitions of the columns of the target table with the source columns of your complex query ...
SELECT SourceColumns.[name] AS SourceColumnName, SourceColumns.[type] AS SourceColumnType, SourceColumns.[length] AS SourceColumnLength, DestinationColumns.[name] AS SourceColumnName, DestinationColumns.[type] AS SourceColumnType, DestinationColumns.[length] AS SourceColumnLength FROM tempdb.sys.syscolumns SourceColumns JOIN tempdb.sys.sysobjects SourceTable ON SourceColumns.[id] = SourceTable.[id] LEFT JOIN sys.syscolumns DestinationColumns ON SourceColumns.colorder = DestinationColumns.colorder LEFT JOIN sys.sysobjects DestinationTable ON DestinationColumns.[id] = DestinationTable.[id] WHERE SourceTable.Name = '##MyResults' AND DestinationTable.Name = 'Publications'
You can adapt this query to filter to certain types of columns (you know that the problem is with string or binary data), and also where the length of the source column is longer than the destination columns. Armed with this information, you should be left with a few columns that could lead to truncation and start your search there.
TIP! Check destination columns for ON INSERT TRIGGERS !!