我正在尝试使用openquery和临时表更新表。每当我执行查询时,我都会收到错误The multi-part identifier "#tempTable.PERMITEE" could not be bound.
The multi-part identifier "#tempTable.BILLTOPERSON" could not be bound.
我不确定我做错了什么,一切似乎都是正确的。非常感谢帮助。
谢谢
这是我的查询
BEGIN TRANSACTION
DROP TABLE #tempTable;
SELECT [EN_ID], [PERMITEE], [BILLTOPERSON] INTO #tempTable FROM LakeEncroachments
SELECT * FROM #tempTable
UPDATE OPENQUERY([GIS-DB1], 'SELECT [EN_ID], [PERMITEE], [BILLTOPERSON] FROM [NaturalResources].[sde].[LAKEMANAGEMENT_LAKEENCROACHMENTS]')
SET [PERMITEE] = #tempTable.[PERMITEE], [BILLTOPERSON] = #tempTable.[BILLTOPERSON]
WHERE [EN_ID] IN (SELECT [EN_ID] FROM #tempTable)
答案 0 :(得分:2)
缺少的是OpenQuery和临时表之间的连接。
更新查询应该类似于:
UPDATE oq
SET oq.[PERMITEE] = tt.[PERMITEE],
oq.[BILLTOPERSON] = tt.[BILLTOPERSON]
FROM OPENQUERY([GIS-DB1], 'SELECT [EN_ID], [PERMITEE], [BILLTOPERSON] FROM [NaturalResources].[sde].[LAKEMANAGEMENT_LAKEENCROACHMENTS]') AS oq
JOIN #tempTable AS tt ON oq.[EN_ID] = tt.[EN_ID]