我想选择分层数据并将其插入表格中.因此我需要在插入中使用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关键字.如何在存储过程中执行此类插入?
谢谢!