我正在尝试将此查询的记录插入到临时表中。任何帮助或建议都会有所帮助
insert into #AddRec
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
我正在尝试将此查询的记录插入到临时表中。任何帮助或建议都会有所帮助
insert into #AddRec
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
这可能有助于它稍微简化您的查询。
create table #AddRec(id int) ;
insert into #addrec
select ed.id
from stg right join
ed on stg.id=ed.id
where stg.id is null;
select * from #Addrec
如果您需要表中的更多字段,请将定义添加到临时表中并将它们添加到选择行中
;WITH Q AS
(
select *
from stg di
right join
ED bp
on
bp.ID = di.ID
except
select *
from stg di
inner join
ED bp
on
bp.ID = di.ID
)
INSERT INTO #AddRec(... list of fields ...)
SELECT (... list of fields ...) FROM Q
如果您想从头开始创建临时表,只需将插入替换为:
SELECT (... list of fields ...)
INTO #AddRec
FROM Q
如果您的选择返回与插入表的字段计数匹配,这应该可以工作!
insert into tbl1 (field1,field2)
select field1,field2 from.................
最简单的方法
select *
into #AddRec
from stg di
right join ED bp on bp.ID = di.ID
except
select * from stg di
inner join ED bp on bp.ID = di.ID