且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CTE查询SQL Server中的解析错误

更新时间:2023-02-02 22:46:23



common_table_expression

列名

在公用表表达式中指定列名。不允许在单个CTE定义中使用重复的名称。 指定的
列名的数量必须与CTE_query_definition的结果
集中的列数匹配。

Specifies a column name in the common table expression. Duplicate names within a single CTE definition are not allowed. The number of column names specified must match the number of columns in the result set of the CTE_query_definition.

只有在
查询定义中提供了所有结果列的唯一名称时,列名列表才是可选的

将列 HierarchyLevel 添加到 cte 列列表中:

WITH DependencyHierarchy(processName,dependProcessName, HierarchyLevel)
AS
(
   ...
)

LiveDemo

或将其保留为空(列名将从第一个 SELECT ):

or just leave it empty (column names will be derived from first SELECT):

WITH DependencyHierarchy AS
(
   ...
)

LiveDemo2