共四级部门(有的只有3级) 现要对其编号 如:001010101 县委 县委直属事业机构 党校
001010101 县委 县委直属事业机构 党校
001010101 县委 县委直属事业机构 党校
001010201 县委 县委直属事业机构 老干局
001010201 县委 县委直属事业机构 老干局
001010201 县委 县委直属事业机构 老干局
001010201 县委 县委直属事业机构 老干局
001010201 县委 县委直属事业机构 老干局
001010301 县委 县委直属事业机构 党研室(县志办)
001010301 县委 县委直属事业机构 党研室(县志办)
001010301 县委 县委直属事业机构 党研室(县志办)在最前面加个字段把编号写进去县委 县委直属事业机构 党校
县委 县委直属事业机构 党校
县委 县委直属事业机构 党校
县委 县委直属事业机构 老干局
县委 县委直属事业机构 老干局
县委 县委直属事业机构 老干局
县委 县委直属事业机构 老干局
县委 县委直属事业机构 老干局
县委 县委直属事业机构 党研室(县志办)
县委 县委直属事业机构 党研室(县志办)
县委 县委直属事业机构 党研室(县志办)
县委 县委直属事业机构 档案馆(档案局) 档案局领导
县委 县委直属事业机构 档案馆(档案局) 档案局领导
县委 县委直属事业机构 档案馆(档案局) 档案局领导
县委 县委直属事业机构 档案馆(档案局) 档案局办公室
县委 县委直属事业机构 档案馆(档案局) 档案局办公室
县委 县委直属事业机构 档案馆(档案局) 档案局办公室
县委 县委直属事业机构 档案馆(档案局) 档案局办公室
县委 县委直属事业机构 档案馆(档案局) 档案局办公室
县委 县委直属事业机构 档案馆(档案局) 档案局执法监督科
县委 县委直属事业机构 档案馆(档案局) 档案局执法监督科
县委 县委直属事业机构 档案馆(档案局) 档案局保管利用科
县委 县委直属事业机构 档案馆(档案局) 档案局保管利用科
县委 县委直属事业机构 档案馆(档案局) 档案局史料编研科
县委 县委直属事业机构 档案馆(档案局) 档案局史料编研科
县委 群团机构 总工会
县委 群团机构 总工会
县委 群团机构 团县委
县委 群团机构 团县委 希望办
县委 群团机构 团县委 希望办
县委 群团机构 团县委 少先队办公室
县委 群团机构 妇联
县委 群团机构 妇联
县委 群团机构 妇联
县委 群团机构 妇联
县委 群团机构 妇联 综合办
县委 群团机构 妇联 妇儿工委办
县委 群团机构 科协
县委 群团机构 科协
县委 群团机构 科协
县委 群团机构 工商联
县委 群团机构 工商联
县委 群团机构 工商联
县委 群团机构 工商联
人大 人大直属事业机构 党校
人大 人大直属事业机构 党校
人大 人大直属事业机构 党校
人大 人大直属事业机构 老干局
人大 人大直属事业机构 老干局
人大 人大直属事业机构 老干局
人大 人大直属事业机构 老干局
人大 人大直属事业机构 老干局
人大 人大直属事业机构 党研室(县志办)
人大 人大直属事业机构 党研室(县志办)
人大 人大直属事业机构 党研室(县志办)
人大 人大直属事业机构 档案馆(档案局) 档案局领导
人大 人大直属事业机构 档案馆(档案局) 档案局领导
人大 人大直属事业机构 档案馆(档案局) 档案局领导
人大 人大直属事业机构 档案馆(档案局) 档案局办公室
人大 人大直属事业机构 档案馆(档案局) 档案局办公室
人大 人大直属事业机构 档案馆(档案局) 档案局办公室
人大 人大直属事业机构 档案馆(档案局) 档案局办公室
人大 人大直属事业机构 档案馆(档案局) 档案局办公室
人大 人大直属事业机构 档案馆(档案局) 档案局执法监督科
人大 人大直属事业机构 档案馆(档案局) 档案局执法监督科
人大 人大直属事业机构 档案馆(档案局) 档案局保管利用科
人大 人大直属事业机构 档案馆(档案局) 档案局保管利用科
人大 人大直属事业机构 档案馆(档案局) 档案局史料编研科
人大 人大直属事业机构 档案馆(档案局) 档案局史料编研科
人大 群团机构 总工会
人大 群团机构 总工会
人大 群团机构 团人大
人大 群团机构 团人大 希望办
人大 群团机构 团人大 希望办
人大 群团机构 团人大 少先队办公室
人大 群团机构 妇联
人大 群团机构 妇联
人大 群团机构 妇联
人大 群团机构 妇联
人大 群团机构 妇联 综合办
人大 群团机构 妇联 妇儿工委办
人大 群团机构 科协
人大 群团机构 科协
人大 群团机构 科协
人大 群团机构 工商联
人大 群团机构 工商联
人大 群团机构 工商联
人大 群团机构 工商联

解决方案 »

  1.   

    lkddy
     
    (lkddy) 等 级: 
    结帖率:0.00% 
      

  2.   


    create table t1(col_1 nvarchar(40),col_2 nvarchar(40),col_3 nvarchar(40),col_4 nvarchar(40))
    insert into t1
    select '县委','县委直属事业机构','党校','' union all
    select '县委','县委直属事业机构','党校','' union all
    select '县委','县委直属事业机构','老干局','' union all
    select '县委','县委直属事业机构','党研室(县志办)','' union all
    select '县委','县委直属事业机构','档案馆','档案局领导' union all
    select '县委','县委直属事业机构','档案馆','档案局办公室' union all
    select '县委','县委直属事业机构','档案馆','档案局办公室' union all
    select '县委','群团机构','总工会','' union all
    select '县委','群团机构','总工会','' union all
    select '人大','人大直属事业机构','党校','' union all
    select '人大','人大直属事业机构','档案馆(档案局)','档案局执法监督科' union all
    select '人大','群团机构','总工会',''
    goalter table t1
    add id varchar(10)
    ;with cte as
    (
    select dense_rank() over (order by col_1)i,* from t1
    ),cta as
    (
    select dense_rank() over (partition by col_1 order by col_2)ii,* from cte
    ),ctc as
    (
    select dense_rank() over (partition by col_1 order by col_3)iii,* from cta
    ),ctd as
    (
    select dense_rank() over (partition by col_1 order by col_4)iiii,* from ctc
    )
    select id = right('00000'+ltrim(i)+'0'+ltrim(ii)+'0'+ltrim(iii)+'0'+ltrim(iii),9),
    col_1,col_2,col_3,col_4
    from ctddrop table t1id                 col_1                                    col_2                                    col_3                                    col_4
    ------------------ ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------
    001020101          人大                                       人大直属事业机构                                 党校                                       
    001020202          人大                                       人大直属事业机构                                 档案馆(档案局)                                 档案局执法监督科
    001010303          人大                                       群团机构                                     总工会                                      
    002020101          县委                                       县委直属事业机构                                 党校                                       
    002020101          县委                                       县委直属事业机构                                 党校                                       
    002020202          县委                                       县委直属事业机构                                 党研室(县志办)                                 
    002020303          县委                                       县委直属事业机构                                 档案馆                                      档案局领导
    002020303          县委                                       县委直属事业机构                                 档案馆                                      档案局办公室
    002020303          县委                                       县委直属事业机构                                 档案馆                                      档案局办公室
    002020404          县委                                       县委直属事业机构                                 老干局                                      
    002010505          县委                                       群团机构                                     总工会                                      
    002010505          县委                                       群团机构                                     总工会                                      (12 行受影响)
      

  3.   


    create table t1(col_1 nvarchar(40),col_2 nvarchar(40),col_3 nvarchar(40),col_4 nvarchar(40))
    insert into t1
    select '县委','县委直属事业机构','党校','' union all
    select '县委','县委直属事业机构','党校','' union all
    select '县委','县委直属事业机构','老干局','' union all
    select '县委','县委直属事业机构','党研室(县志办)','' union all
    select '县委','县委直属事业机构','档案馆','档案局领导' union all
    select '县委','县委直属事业机构','档案馆','档案局办公室' union all
    select '县委','县委直属事业机构','档案馆','档案局办公室' union all
    select '县委','群团机构','总工会','' union all
    select '县委','群团机构','总工会','' union all
    select '人大','人大直属事业机构','党校','' union all
    select '人大','人大直属事业机构','档案馆(档案局)','档案局执法监督科' union all
    select '人大','群团机构','总工会',''
    goalter table t1
    add id varchar(10)
    go
    ;with cte as
    (
    select dense_rank() over (order by col_1)i,* from t1
    ),cta as
    (
    select dense_rank() over (partition by col_1,i order by col_2)ii,* from cte
    ),ctc as
    (
    select dense_rank() over (partition by col_1,ii order by col_3)iii,* from cta
    ),ctd as
    (
    select dense_rank() over (partition by col_1,iii order by col_4)iiii,* from ctc
    )
    update t1
    set id = temp.id from(
    select id = right('00000'+ltrim(i)+'0'+ltrim(ii)+'0'+ltrim(iii)+'0'+ltrim(iiii),9),
    col_1,col_2,col_3,col_4
    from ctd)temp where t1.col_1 = temp.col_1 and t1.col_2 = temp.col_2
    and t1.col_3 = temp.col_3 and t1.col_4 = temp.col_4
    select id,col_1,col_2,col_3,col_4 from t1 order by iddrop table t1id         col_1                                    col_2                                    col_3                                    col_4
    ---------- ---------------------------------------- ---------------------------------------- ---------------------------------------- ----------------------------------------
    001010101  人大                                       群团机构                                     总工会                                      
    001020101  人大                                       人大直属事业机构                                 党校                                       
    001020201  人大                                       人大直属事业机构                                 档案馆(档案局)                                 档案局执法监督科
    002010101  县委                                       群团机构                                     总工会                                      
    002010101  县委                                       群团机构                                     总工会                                      
    002020101  县委                                       县委直属事业机构                                 党校                                       
    002020101  县委                                       县委直属事业机构                                 党校                                       
    002020201  县委                                       县委直属事业机构                                 党研室(县志办)                                 
    002020301  县委                                       县委直属事业机构                                 档案馆                                      档案局办公室
    002020301  县委                                       县委直属事业机构                                 档案馆                                      档案局办公室
    002020302  县委                                       县委直属事业机构                                 档案馆                                      档案局领导
    002020401  县委                                       县委直属事业机构                                 老干局                                      (12 行受影响)