declare @set varchar(8000)
SELECT @set=isnull(@set,'')+名称+'/' from Name
select substring(@set,0,len(@set)-1)
------------------------------------------
中国/云南省/保山市/腾冲
根据自己的业务情况再加where 条件
估计只能用存储函数写了。
create or replace function GetPath(
@v_id varchar2)
return varchar2
is
v_name varchar2(255);
v_path varchar2(255);
begin
select name into v_name from table where id = substr(v_id, 0, 2);
v_path := v_path | v_name;
select name into v_name from table where id = substr(v_id, 1, 2);
v_path := v_path | v_name;
select name into v_name from table where id = substr(v_id, 3, 2);
v_path := v_path | v_name;
select name into v_name from table where id = substr(v_id, 4, 2);
v_path := v_path | v_name;
return v_path;
end GetPath;
select GetPath(ID) from table;
select 名称+'/' from 表 where 1=1 for xml path('')
where那里写你自己的条件吧。
这个完全可以在程序来实现,把每个名称先分别查询出来,
string address="中国"+“/"+"云南省"+“/"+"保定市"+“/"+"腾冲县",
declare @res varchar(1000)
select @res = isnull(@res,'')+名称+'/' from 表名 where 代码 like '101%' order by 代码
select @res