2011-03-28 95 views
2

使用SQL Server 2008(R2)。 我有两个表在不同的数据库(具有相同的列数和数据类型 - 但不同的大小) 。我将值从一个值插入另一个值, - 但问题是源表中有:nvarchar(200),而目标表中有一个类型为nvarhchar(100)的字段。 并且在与超过100个字符更大的字段源表数据,所以该错误:字符串截断,ANSI_WARNINGS关闭

*String or binary data would be truncated is thrown.* 

我使用

-- 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 

然而,这是,抛它看起来像这样的错误的尝试: “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.

有关如何解决此问题的任何想法?

回答

3

你可以自己截断数据:

insert into desttable(destcolumn) 
select left(sourcecolumn, 100) from sourcetable