我正在尝试对远程服务器实施一波更新。这是我正在使用的查询:
update openquery(portal_mysql2, 'select * from memberstest_SL')
set fte_actual= (select [Full-time_enrollment]
FROM [BIDEV].[dbo].[TBL_IPEDS_HISTORY_NEW]
inner join openquery(Portal_mysql2, ' select * from memberstest_SL') on cast(unitid as varchar) = Right(nces_agencyid, 6)
where [year] = Year(GetDate())-2
and [Full-time_enrollment] <> '0'
and [Full-time_enrollment] is not null
and cast(unitid as varchar) = Right(nces_agencyid, 6)
)
这将返回错误:
子查询返回了多个值
这是有道理的,因为我尝试使用源表中的相应值更新多个记录。
任何人都知道如何实现这一目标?
答案 0 :(得分:0)
请尝试使用类似的东西:
update qe
set fte_actual = Full-time_enrollment
from openquery(portal_mysql2, 'select * from memberstest_SL') qe
inner join [BIDEV].[dbo].[TBL_IPEDS_HISTORY_NEW] tab on CAST(unitid as varchar) = RIGHT(nces_agencyid, 6)
where year = YEAR(GETDATE()) - 2
and ISNULL(Full-time_enrollment, '0') != '0'
and CAST(unitid as varchar) = RIGHT(nces_agencyid, 6)