WITHMakeModuleNoAS(SELECT''ASLEVEL_,c.*FROMTABLE_NamecWHEREc.Guid_=@PnGuidUNIONALLSELECT''ASLEVEL_,c.*FROMTABLE_NamezINNERJOINTABLE_NamecONz.Guid_=c.Guid4ChKB)为每一级查询... WITH MakeModuleNo AS (
SELECT '' AS LEVEL_,c.*
FROM TABLE_Name c
WHERE c.Guid_ = @PnGuid
UNION ALL
SELECT '' AS LEVEL_,c.*
FROM TABLE_Name z INNER JOIN TABLE_Name c ON z.Guid_ = c.Guid4ChKB
)
为每一级查询编一个数字代号,同一级的拥有同一个编号
示例代码如下:
;with a as(select * from table_a),
b as (select * from a where id in(3,4,5))
select * from b
记得一定要有逗号间隔开两个查询,Z后一个查询前是没有逗号的