小编jzz*_*zzh的帖子

TSQL:WITH cteTABLE插入other_table

可能重复:
关键字'with'...前面的语句附近的语法不正确必须以分号结束

我想选择分层数据并将其插入表格中.因此我需要在插入中使用WITH语句.

这很好用:

create table test_table
(
 id int
)   

with t_table 
as
(select 12345 wert)
insert into test_table (id)
select wert from t_table
Run Code Online (Sandbox Code Playgroud)

但这会生成"WITH关键字附近的错误语法"错误:

CREATE PROCEDURE p_insert_test
AS
BEGIN

with t_table 
as
(select 12345 wert)
insert into test_table (id)
select wert from t_table

END
Run Code Online (Sandbox Code Playgroud)

我猜T-SQL在INSERT关键字之前不喜欢WITH关键字.如何在存储过程中执行此类插入?

谢谢!

sql t-sql sql-server with-statement insert-select

1
推荐指数
1
解决办法
1635
查看次数

标签 统计

insert-select ×1

sql ×1

sql-server ×1

t-sql ×1

with-statement ×1