我使用的是Microsoft SQL Server,在编写此代码时,我发现" Inner"而且" ="在SET行内。我已经调查了这一点并认为一切都设置正确,有人可以指出为什么可能吗?
USE [db1]
GO
UPDATE a.[table1]
INNER JOIN a.[table1] = a.[table2]
ON a.[table1].[field1] = a.[table2].[field1]
SET [field2] = a.[table2].[field2]
WHERE [ID] IN (SELECT #TempTable.[ID] FROM #TempTable)
答案 0 :(得分:1)
好吧,我完全不知道你从UPDATE
获得JOIN
的语法在哪里,但它很混乱。这应该是正确的代码:
UPDATE t1
SET t1.field2 = t2.field2
FROM dbo.table1 t1
INNER JOIN dbo.table2 t2
ON t1.field1 = t2.field2
WHERE [ID] IN (SELECT [ID] FROM #TempTable);
答案 1 :(得分:0)
UPDATE a
SET [field2] = a.[table2].[field2]
from a.[table1]
INNER JOIN a.[table1] = a.[table2]
ON a.[table1].[field1] = a.[table2].[field1]
WHERE [ID] IN (SELECT #TempTable.[ID] FROM #TempTable)
看看它是否正常工作
答案 2 :(得分:0)
尝试以下
UPDATE a.[table1]
SET [field2] = a.[table2].[field2]
From a.[table1]
INNER JOIN a.[table2]
ON a.[table1].[field1] = a.[table2].[field1]
WHERE [ID] IN (SELECT #TempTable.[ID] FROM #TempTable)
答案 3 :(得分:0)
使用内部联接更新
UPDATE T1
SET T1.[field2] = T2.[field2]
FROM a.[table1] AS T1
INNER JOIN a.[table2] AS T2
ON T1.[field1] = T2.[field1]