通过链接服务器从SQL Server查询iSeries DB2 varchar(32000)列时出错

m4pnthwp  于 2023-01-26  发布在  DB2
关注(0)|答案(1)|浏览(172)

我正在将iSeries DB2数据库迁移到SQL Server(手动-当前未使用SSMA)。我有一个varchar(32000)类型的DB2列。当我尝试使用openquery通过链接服务器从SQL Server进行查询时,我收到错误“Requested conversion is not supported”。如何使用SQL脚本迁移此数据?
下面是链接服务器上的查询示例:

select MYVARCHAR32000COLUMN
from   openquery(MYDB2LINKEDSERVER, 'select MYVARCHAR32000COLUMN from MYDB2DB.MYDB2TABLE')

OLE DB provider "MSDASQL" for linked server "MYDB2LINKEDSERVER" returned message "Requested conversion is not supported.".
Msg 7341, Level 16, State 2, Line 2304
Cannot get the current row value of column "[MSDASQL].MYVARCHAR320000COLUMN" from OLE DB provider "MSDASQL" for linked server "MYDB2LINKEDSERVER".
vs91vp4v

vs91vp4v1#

为了在不更改链接服务器驱动程序的情况下迁移这些数据,我最终在源表中添加了4个CLOB列,然后在目标SQL Server表中将这4个部分转换为varchar(8000)。
在DB2(源)上:

alter table MYDB2.MYTABLE add MYCOL_1 CLOB;
alter table MYDB2.MYTABLE add MYCOL_2 CLOB;
alter table MYDB2.MYTABLE add MYCOL_3 CLOB;
alter table MYDB2.MYTABLE add MYCOL_4 CLOB;

update MYDB2.MYTABLE set MYCOL_1 = trim(substring(MYCOL, 1, 8000));
update MYDB2.MYTABLE set MYCOL_2 = trim(substring(MYCOL, 8001, 16000));
update MYDB2.MYTABLE set MYCOL_3 = trim(substring(MYCOL, 16001, 24000));
update MYDB2.MYTABLE set MYCOL_4 = trim(substring(MYCOL, 24001, 32000));

然后在SQL Server(目标)上:

select cast(MYCOL_1 as varchar(8000)) + cast(MYCOL_2 as varchar(8000)) + cast(MYCOL_3 as varchar(8000)) + cast(MYCOL_4 as varchar(8000)) MYCOL
from   openquery(MYDB2LINKEDSERVER, 'select MYCOL_1, MYCOL_2, MYCOL_3, MYCOL_4 from MYDB2.MYTABL')

相关问题