update PT_EQCategory 
set ParentCode=CategoryOrder 
where rtrim(ltrim(CategoryCode))=rtrim(ltrim(ParentCode))

解决方案 »

  1.   

    如果是回车换行等控制字符:
    update PT_EQCategory 
    set ParentCode=CategoryOrder 
    where replace(replace(
        rtrim(ltrim(CategoryCode))
        ,char(10),''),char(13),'')
       =replace(replace(
        rtrim(ltrim(ParentCode))
        ,char(10),''),char(13),'')
      

  2.   

    CategoryCode                  CategoryOrder  ParentCode
    0                                 0 -1
    39f96bd1989046e7a261930e811a2c37 7 0
    db5169ec42bc41278aec47bd12ff2a45 32 39f96bd1989046e7a261930e811a2c37
    dbf79f54c7cb4d6ebb9003b34254f1b0 19 ca387cc160ee4ab5bd446e3e42cbd8a3
    e1ca962c542c4a318f12ecf1d7826388 35 68caf92579364099b2c4b5e329925953
    e9d8f869f84945f983c47fbd1ddeaf92 199 ca387cc160ee4ab5bd446e3e42cbd8a3
    f9eb23cad65c4ce193ccc956676c9023 20 ca387cc160ee4ab5bd446e3e42cbd8a3
    fab2a8b17fd94a64ac181f8858b07a1c 31 7805131976a54412bb1ce1309b9f9e70
      
    问题补充数据太多粘了部分
      

  3.   

    CategoryCode /CategoryOrder /ParentCode
    0 /0 /-1
    39f96bd1989046e7a261930e811a2c37  / 7 /0
    db5169ec42bc41278aec47bd12ff2a45  / 32 /39f96bd1989046e7a261930e811a2c37
    dbf79f54c7cb4d6ebb9003b34254f1b0   / 19 /ca387cc160ee4ab5bd446e3e42cbd8a3
    e1ca962c542c4a318f12ecf1d7826388   / 35 /68caf92579364099b2c4b5e329925953
    e9d8f869f84945f983c47fbd1ddeaf92   / 199 /ca387cc160ee4ab5bd446e3e42cbd8a3
    f9eb23cad65c4ce193ccc956676c9023  / 20 /ca387cc160ee4ab5bd446e3e42cbd8a3
    fab2a8b17fd94a64ac181f8858b07a1c   / 31 /7805131976a54412bb1ce1309b9f9e70谢谢 几位兄弟,  问题还没有解决   影响行数都是0
      

  4.   

    我直接执行 
    select * from pt_PT_EQCategory 
    where rtrim(ltrim(CategoryCode))=rtrim(ltrim(ParentCode))  查找 记录为空
    但是 CategoryCode和ParentCode 字段肯定是有相同的
      

  5.   

    都是我 表述不请  我感觉不应该这么 写  
    我说的是CategoryCodE  中的 值去对应  ParentCode 字段  的所有值  不是在一条记录中 相同 
      

  6.   

    都是NULL?update PT_EQCategory 
    set ParentCode=CategoryOrder 
    where isnull(replace(replace( rtrim(ltrim(CategoryCode)) ,char(10),''),char(13),''),'') 
         =isnull(replace(replace( rtrim(ltrim(ParentCode)) ,char(10),''),char(13),''),'')
      

  7.   

    select * from PT_EQCategory a where
    exists (select 1 from PT_EQCategory b where b.ParentCode=a.CategoryCode)
      

  8.   

    原来是这样...UPDATE @PT_EQCategory 
    SET
    ParentCode = CategoryOrder
    FROM @PT_EQCategory U
    WHERE EXISTS(
    SELECT 1 FROM @PT_EQCategory P
    WHERE U.CategoryCode = P.ParentCode
    )
      

  9.   

    好像少写了个别名DECLARE @PT_EQCategory TABLE (CategoryCode varchar(50), CategoryOrder int, ParentCode varchar(50))
    INSERT INTO @PT_EQCategory
    SELECT '0', 1, '-1' UNION ALL
    SELECT '39f96bd1989046e7a261930e811a2c37', 7, '0' UNION ALL
    SELECT 'db5169ec42bc41278aec47bd12ff2a45', 32, '39f96bd1989046e7a261930e811a2c37' UNION ALL
    SELECT 'dbf79f54c7cb4d6ebb9003b34254f1b0', 19, 'ca387cc160ee4ab5bd446e3e42cbd8a3' UNION ALL
    SELECT 'e1ca962c542c4a318f12ecf1d7826388', 35, '68caf92579364099b2c4b5e329925953' UNION ALL
    SELECT 'e9d8f869f84945f983c47fbd1ddeaf92', 199, 'ca387cc160ee4ab5bd446e3e42cbd8a3' UNION ALL
    SELECT 'f9eb23cad65c4ce193ccc956676c9023', 20, 'ca387cc160ee4ab5bd446e3e42cbd8a3' UNION ALL
    SELECT 'fab2a8b17fd94a64ac181f8858b07a1c', 31, '7805131976a54412bb1ce1309b9f9e70'--SELECT * FROM @PT_EQCategoryUPDATE @PT_EQCategory
    SET
    ParentCode = U.CategoryOrder
    FROM @PT_EQCategory U
    WHERE EXISTS(
    SELECT 1 FROM @PT_EQCategory P
    WHERE U.CategoryCode = P.ParentCode
    )SELECT * FROM @PT_EQCategory
      

  10.   

    我的表达能力太困难了
    在从说一遍吧一个表  TB 有三个字段  A B C 
    a         b         c 
    1         5         2 
    2         6         1
    现在要把C中所有 值都替换成B中的值  条件是C中的一个值 和A 中所有值去对应   找到和A中对应的字段 
    语句执行后的结果应该是
    A        B        C
    1        5        6
    2        6        5 
      

  11.   

    update Tb
    set C= (select top 1 B from Tb as X where X.C=Tb.a)
      

  12.   

    select *
    from PT_EQCategory a 
    join PT_EQCategory b on b.ParentCode=a.CategoryCode
    如果b.CategoryOrder是你要的数据:
    update PT_EQCategory set 
    ParentCode = b.CategoryOrder
    from PT_EQCategory a 
    join PT_EQCategory b on b.ParentCode=a.CategoryCode
      

  13.   

    update PT_EQCategory set 
    ParentCode = b.CategoryOrder
    from PT_EQCategory a 
    join PT_EQCategory b on b.ParentCode=a.CategoryCode消息 8154,级别 16,状态 1,第 1 行
    表 'PT_EQCategory' 不明确。
      

  14.   

    update a set 
        ParentCode = b.CategoryOrder 
    from PT_EQCategory a 
    join PT_EQCategory b on b.ParentCode=a.CategoryCode