Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
Created September 12, 2013 13:22
Show Gist options
  • Select an option

  • Save ichiroku11/6537195 to your computer and use it in GitHub Desktop.

Select an option

Save ichiroku11/6537195 to your computer and use it in GitHub Desktop.
セット演算子を使った select into と insert into select
if object_id('tempdb..#Test') is not null
drop table #Test;
select *
into #Test
from (values(1), (2)) as Test(Value)
union all
select *
from (values(3), (4)) as Test(Value);
select *
from #Test;
/*
Value
-----------
1
2
3
4
*/
insert into #Test
select *
from (values(5), (6)) as Test(Value)
except
select *
from (values(6), (7)) as Test(Value);
select *
from #Test;
/*
Value
-----------
1
2
3
4
5
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment