2011-03-09 14 views
0
INSERT INTO OPENROWSET('MSDASQL', 'Driver=PostgreSQL Unicode;uid=postgres;Server=localhost;port=5432;database=data;pwd=xxx', 
    'select SanctionId,SchemeType,SchemeCode,CorrigendumStatus,AttendumStatus,yearofPlan,ReceivedDate from tesing WHERE SanctionId = ''-1'' ') 
select SanctionId,SchemeType,SchemeCode,CorrigendumStatus,AttendumStatus,yearofPlan,ReceivedDate from testing where SanctionId=1103 

在執行上面的查詢時,我收到以下錯誤:錯誤使用OPENROWSET針對特定記錄

Msg 8152, Level 16, State 10, Line 1
String or binary data would be truncated. The statement has been terminated.

誰能幫我解決這個問題?

回答

1

您必須根據目標列定義檢查源數據。

這種情況發生時您嘗試插入,比方說,100個字符轉換成一個varchar(50)列

+0

謝謝你的回覆,但是當我手動複製列數據我的意思創建插入腳本並運行它是工作,但當我起訴openrowset時出現錯誤 – kallem 2011-03-09 08:02:05

+0

@kallem:錯誤信息由SQL Server生成,而不是由PostgreSQL生成。因此,您可以直接在PostgreSQL中執行的操作可能不適用於您在SQL Server中允許執行的操作。只要遵照建議並在適當的地方使用SUBSTRING或CAST即可。 – 2011-03-09 12:46:14