HI,
how can I select repeatedly into the same temporary table and then return the full outcome.
something like
select
col1,
col2
into #temp
where
col4="abc"
and col5=10
select
col1,
col10
into #temp
where
col4="dbe"
and col5=15
select * from #temp
开发者_StackOverflow中文版I tried it, and it returned only the first part.
/*First one creates the table*/
select
col1,
col2
into #temp
from something
where
col4="abc"
and col5=10
/*Now insert into the table that you just created*/
insert into #temp
select
col1,
col10
from something
where
col4="dbe"
and col5=15
select * from #temp
You could also do
select
col1,
col2
into #temp FROM (
select
col1,
col2
from something
where
col4="abc"
and col5=10
union all
select
col1,
col10
from something
where
col4="dbe"
and col5=15) derived
The above code should end up in error. You should insert into after the first select into. Try this:
select
col1,
col2
into #temp
where
col4="abc"
and col5=10;
insert into #temp
select
col1,
col10
where
col4="dbe"
and col5=15;
select * from #temp
精彩评论