SQL Server WITH 语句

标签 sql sql-server-2008 stored-procedures

我的目标是从一个 CTE 中选择结果,并在同一过程中用另一个 CTE 插入到另一个表中。怎么做?

我的错误是...

invalid object name xy.



我的查询是
WITH ds
(
    Select a, b, c 
    from test1    
),
xy
(
    select d, e, f 
    from test2 
    where (uses conditions from ds)    
)
Select * 
from ds  (the result set of ds, am exporting this to csv)

Insert into AuditTest
(
  Select * from xy
)

最佳答案

CTE 仅适用于一个查询,但您似乎可以在每个查询中使用 CTE:

WITH ds AS
(
  Select a, b, c from test1    
)
Select * from ds  (the result set of ds, am exporting this to csv)


WITH xy AS
(
 select d,e,f from test2 where (uses conditions from test1)    
)
Insert into AuditTest
(
  Select * from xy
)

关于SQL Server WITH 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28725389/

相关文章:

sql - 检索每个组中的最后一条记录-MySQL

sql - 有没有办法延迟存储过程执行计划的编译?

sql-server-2008 - Select 语句中的 bool 逻辑

mysql - 如何拆分逗号分隔值

mysql - 我如何使用 mysql 过程将 sql 查询的结果分配给变量?

mysql - 如何在一行中包含多行引用?

MySQL COUNT 件库存商品

asp.net - ASP.NET 2008 Express 不支持 CREATE TABLE SQL 构造或语句

sql-server-2008 - T-SQL 错误处理在 "BEGIN CATCH" block 中完全关闭了吗?

postgresql - 如何分析 plpgsql 程序