Using SQL Server 2008 (R2).
I have two tables in different databases (with same # of columns and datatypes – but different sizes)
. I’m inserting values from one to another, – but the problem is that the source table has say: nvarchar(200) and the destination table has a field of type nvarhchar(100).
And there is data in the source table with larger fields than 100 characters, so the error:
*String or binary data would be truncated is thrown.*
I tried using the
-- SourceServer is passed in at command prompt (batch)
SET ANSI_WARNINGS OFF
GO
INSERT INTO DestinationTable(col1, col2,...)
SELECT col1, col2, ...
FROM $SourceServer.dbo.SourceTable
SET ANSI_WARNINGS ON
GO
This is however, throwing an error which looks like this:
“INSERT failed because the following SET options have incorrect settings: 'ANSI_WARNINGS'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.“
Any ideas on how I can fix this?
You could truncate the data yourself: