Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql temp table with except

I am trying to insert the records that come of this query into a temp table. Any help or suggestion will be helpful

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 
like image 763
knahs Avatar asked Mar 16 '26 01:03

knahs


1 Answers

This may help it simplifies your query a little.

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

If you need more fields from the tables add the definitions into the temp table and add them into the select line

like image 139
Ian Kenney Avatar answered Mar 18 '26 14:03

Ian Kenney



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!