3

我正在尝试将此查询的记录插入到临时表中。任何帮助或建议都会有所帮助

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 
4

4 回答 4

4

可能有助于它稍微简化您的查询。

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

如果您需要表中的更多字段,请将定义添加到临时表中并将它们添加到选择行中

于 2013-04-26T23:57:58.150 回答
1
;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
于 2013-04-29T12:33:51.113 回答
0

如果您的选择返回与插入表的字段计数匹配,这应该可以工作!

  insert into tbl1 (field1,field2)
    select field1,field2 from.................
于 2013-04-26T23:44:51.353 回答
0

最简单的方法

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
于 2021-03-23T15:12:33.890 回答