17,382
社区成员




declare @tmp table(pid varchar(10),cid varchar(20))
insert into @tmp(pid,cid)
select '0','42032-0001' union all
select '.1','42032-0001-001' union all
select '..2','1041-0261' union all
select '...3','30328-0102-0001' union all
select '0','52032-0001' union all
select '.1','42032-0001-001' union all
select '..2','1041-0261' union all
select '...3','30328-0102-0001'
;with t1 as (
select ROW_NUMBER() over(partition by pid order by pid) as rowid,pid,cid
from @tmp
),t2 as (
select ROW_NUMBER() over(partition by pid order by pid) as rowid,pid,cid
from @tmp where pid = '0'
)
select t2.cid as pid,t1.cid
from t1 left join t2 on t1.rowid = t2.rowid
order by t2.cid
update 表名 set pid=left(cid,10)