我想选择分层数据并将其插入表中。因此我需要在我的插入中使用 WITH 语句。
这工作正常:
create table test_table
(
id int
)
with t_table
as
(select 12345 wert)
insert into test_table (id)
select wert from t_table
但这会产生“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
我猜 T-SQL 不喜欢 INSERT 关键字之前的 WITH 关键字。我怎样才能在存储过程中进行这种插入?
谢谢!