DECLARE @companyid TABLE ( [Id] [int] ); with cte as( select Id from [base].[Company] where Id=123 union all select a.Id from [base].[Company] a,cte b where a.ParentId=b.Id ) INSERT @companyid(id) select Id from cte
1、with 前邊的sql語句需加分號;
2、使用with變量需緊跟with語句;
3、with變量只能緊跟的使用一次;