Reuse results from SQL Server common table expression

前端 未结 3 1585
悲&欢浪女
悲&欢浪女 2021-01-22 07:16

I have a query to retrieve all the modules and child modules for a page, using a common table expression. Is it possible to use the results from the cte more than once?

3条回答
  •  天涯浪人
    2021-01-22 07:40

    You will need split child_modules CTE into two CTE's.

    The first one containing the first SELECT of the current child_modules CTE, then use a second CTE that builds upon child_modules.

    Your final SELECT would then use the third CTE instead of child_modules.

提交回复
热议问题