数据处理4位树代码扩展为6位
原始数据 1?? ?行政后勤?? ?????????0001 方法一: ;with tree as ( select ksdm,ksmc,case len(kswm) when 4 then '' when 8 then '00'+substring(kswm,1,4) when 12 then '00'+substring(kswm,5,4) when 16 then '00'+substring(kswm,9,4) end as p,case len(kswm) when 4 then '00'+kswm when 8 then '00'+substring(kswm,13,4) end as c from ks ),cte as ( -->begin定位点 select ksdm,c as kswm,c,p,1 as levle from tree where p='' -->end union all -->begin select tree.ksdm,tree.ksmc,cte.kswm+tree.c as kswm,tree.c,tree.p,levle+1 as levle from tree inner join cte on tree.p=cte.c -->end ) select * from cte order by kswm方法二: Excel函数 =IF(LEN(C3)>4,CONCATENATE("00",MID(C3,4)),"")
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |