我尝试结合"选择*进入"用"用"
drop table #a
create table #a(a1 int);
insert into #a (a1) values (1),(2);
select * into #b(--I try this syntax and have error mentioned below
with a as
(
select * from #a
)
select * from a
)
错误:关键字'附近的语法错误,用'。
我如何解决此错误?
答案 0 :(得分:2)
您需要将公用表表达式放在实际的insert
:
drop table #a;
create table #a(a1 int);
insert into #a (a1) values (1),(2);
with a as (
select *
from #a
)
select *
into #b
from a;
答案 1 :(得分:1)
可以找到公共表表达式的正确语法here:
drop table #a
create table #a(a1 int)
insert into #a (a1) values (1),(2)
;with a as (
select * from #a
)
select * into #b from a;