typeid  typeno  typename parentid
1 0 全部类别   -1
2 01 东风配件   0
3 02 解放配件   0
4 03 春兰配件   0
5 04 代理配件   0
6 0101 发动机系统 01
7 0102 变速箱系统  01
8 0103 后桥系统   01
9 0104 底盘系统   01
10 0105 车身部件   01
11 010101 康明斯   0101怎么讲parentid的值换成typeid的值

解决方案 »

  1.   

    update tb
    set parentid=typeid
    ?
      

  2.   

    hgjhgghjhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
      

  3.   

    parentid保存的是typeno的值,现在要根据typeno的值找typeid的值
      

  4.   

    select *,parentid_new=(select typeid from tb where parentid=a.typeno)
    from tb a
      

  5.   

    typeid  typeno  typename parentid 
    1 0 全部类别   -1 
    2 01 东风配件   1 
    3 02 解放配件   1 
    4 03 春兰配件   1 
    5 04 代理配件   1 
    6 0101 发动机系统 2 
    7 0102 变速箱系统  2 
    8 0103 后桥系统   2
    9 0104 底盘系统   2 
    10 0105 车身部件   2 
    11 010101 康明斯   6要这个效果 
      

  6.   

    犯了一个低级错误---测试数据---
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([typeid] int,[typeno] varchar(6),[typename] varchar(10),[parentid] varchar(4))
    insert [tb]
    select 1,'0','全部类别','-1' union all
    select 2,'01','东风配件','0' union all
    select 3,'02','解放配件','0' union all
    select 4,'03','春兰配件','0' union all
    select 5,'04','代理配件','0' union all
    select 6,'0101','发动机系统','01' union all
    select 7,'0102','变速箱系统','01' union all
    select 8,'0103','后桥系统','01' union all
    select 9,'0104','底盘系统','01' union all
    select 10,'0105','车身部件','01' union all
    select 11,'010101','康明斯','0101'
     
    ---更新---
    update a
    set a.parentid=b.typeid
    from tb a,tb b
    where a.parentid=b.typeno---查询---
    select * from [tb]---结果---
    typeid      typeno typename   parentid 
    ----------- ------ ---------- -------- 
    1           0      全部类别       -1
    2           01     东风配件       1
    3           02     解放配件       1
    4           03     春兰配件       1
    5           04     代理配件       1
    6           0101   发动机系统      2
    7           0102   变速箱系统      2
    8           0103   后桥系统       2
    9           0104   底盘系统       2
    10          0105   车身部件       2
    11          010101 康明斯        6(所影响的行数为 11 行)
      

  7.   

    select a.*,b.typeno parentid_new
    from tb a join tb b on a.parentid=b.typeno