插入 table 不适用于 select 左连接

Insert into table does not work with select left join

我正在尝试将来自 openrowset 查询的新记录插入 table 中不存在的 table 中。 这是代码:

insert into SRC_TABLE
REP.ID
,REP.COLUMN1
from openrowset (blabla) REP
left join SRC_TABLE TAB on REP.ID = TAB.ID
where TAB.ID is null

我收到错误:

Incorrect syntax near 'REP'.

然而当我运行查询如下:

select
REP.ID
,REP.COLUMN1
from openrowset (blabla) REP
left join SRC_TABLE TAB on REP.ID = TAB.ID
where TAB.ID is null

按预期工作,给我 SRC_TABLE 中不存在的行。 我做错了什么?

INSERT INTO dbo.table1 (...)
SELECT cte.DepartmentID
FROM OPENROWSET('SQLNCLI', 'Server=SQL_2012;Trusted_Connection=yes;',
    'SELECT DepartmentID FROM AdventureWorks2012.HumanResources.Department') cte
LEFT JOIN AdventureWorks2012.HumanResources.Department t ON cte.DepartmentID = t.DepartmentID

你几乎成功了:

insert into table (ID, Column)
select
REP.ID
,REP.COLUMN1
from openrowset (blabla) REP
left join SRC_TABLE TAB on REP.ID = TAB.ID
where TAB.ID is null