2011-03-28 40 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