日期:2014-05-17 浏览次数:20425 次
create table tb(id int,adname varchar(20),pid int)
insert into tb
select 1 ,'广西', 0 union all
select 2 ,'南宁', 1 union all
select 3 ,'玉林', 1 union all
select 4 ,'陆川', 3 union all
select 5 ,'北流', 3 union all
select 6 ,'中镇', 5 union all
select 7 ,'宁明', 2
go
;with t
as
(
select id,adname as adname_t,pid,1 as level,
CAST(adname as varchar(max)) as adname,
cast(right('000'+cast(id as varchar),3) as varchar(max)) as sort
from tb
where id =1 --参数为:where id=1时
union all
select tb.id,tb.adname