我试图将这个查询得到的记录插入到一个临时表中。任何帮助或建议将会有所帮助。
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