with tab as
(
select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=316
union all
select b.Type_Id,b.ParentId,b.Type_Name
from
tab a,
Sys_ParamType_V2_0 b
where a.ParentId=b.Type_Id
)
select * from tab;
with tab as
(
select Type_Id,ParentId,Type_Name from Sys_ParamType_V2_0 where Type_Id=1
union all
select b.Type_Id,b.ParentId,b.Type_Name
from
tab a,
Sys_ParamType_V2_0 b
where b.ParentId=a.Type_Id
)
select * from tab;
with tab as
(
select Type_Id,ParentId,Type_Name,cast(Type_Id as varchar(100)) as fulltypeid
from SKU_ProductType where Type_Id=423
union all
select
b.Type_Id,b.ParentId,b.Type_Name,
cast(a.fulltypeid+','+cast(b.Type_Id as nvarchar(100)) as varchar(100)) as fulltypeid
from
tab a,
SKU_ProductType b
where a.ParentId=b.Type_Id
)
select * from tab ;
423 410 蜂花粉 423
410 347 蜂产品 423,410
347 5 营养食品 423,410,347
5 0 健康保健 423,410,347,5
转载于http://blog.csdn.net/killcwd/article/details/50409352