字段 ID
字段 NAME   内容
 ID  NAME
 1   p_lihao
 2   p_caitou
 3   p_xiaoming 
。怎么修改成
 ID  NAME
 1   lihao
 2   caitou
 3   xiaoming 

解决方案 »

  1.   

    update tb set
        name = stuff(name,1,2,'');
      

  2.   

    update tb set name = substring(name , charindex('-',name) + 1 , len(name)) where charindex('-',name) > 0
      

  3.   

    update tb set
        name = stuff(name,1,2,'')
    where name like 'p_%';
      

  4.   


    update tb set name = substring(name , charindex('-',name) + 1 , len(name)) where charindex('-',name) > 0如果是有规律的,就是1楼update tb set 
        name = stuff(name,1,2,'');
      

  5.   

    忘了转义..update tb set
        name = stuff(name,1,2,'')
    where name like 'p$_%' escape '$';
      

  6.   

    create table tb(ID int,  NAME varchar(20))
    insert into tb values(1 , 'p_lihao') 
    insert into tb values(2 , 'p_caitou') 
    insert into tb values(3 , 'p_xiaoming')
    GOupdate tb set name = substring(name , charindex('_',name) + 1 , len(name)) where charindex('_',name) > 0
    select * from tbdrop table tb /*
    ID          NAME                 
    ----------- -------------------- 
    1           lihao
    2           caitou
    3           xiaoming(所影响的行数为 3 行)*/
      

  7.   

    -------------------------------------------
    --  Author : liangCK 小梁
    --  Comment: 小梁 爱 兰儿
    --  Date   : 2009-09-06 11:02:05
    -------------------------------------------
     
    --> 生成测试数据: @T
    DECLARE @T TABLE (ID INT,NAME VARCHAR(10))
    INSERT INTO @T
    SELECT 1,'p_lihao' UNION ALL
    SELECT 2,'p_caitou' UNION ALL
    SELECT 3,'p_xiaoming' UNION ALL
    SELECT 4,'liang'--SQL查询如下:update @T set
        name = stuff(name,1,2,'')
    where name like 'p$_%' escape '$';select * from @T/*
    ID          NAME
    ----------- ----------
    1           lihao
    2           caitou
    3           xiaoming
    4           liang(4 row(s) affected)
    */
      

  8.   

    update tb set 
        name = stuff(name,1,2,''); 
     
     这个就可以了啊
      

  9.   

    STUFF ( character_expression , start , length ,character_expression ) 参数character_expression    一个字符数据 表达式。character_expression 可以是常量、变量,也可以是字符列或二进制数据列。start    一个整数值,指定删除和插入的开始位置。如果 start 或 length 为负,则返回空字符串。如果 start 比第一个 character_expression 长,则返回空字符串。start 可以是 bigint 类型。length    一个整数,指定要删除的字符数。如果 length 比第一个 character_expression 长,则最多删除到最后一个 character_expression 中的最后一个字符。length 可以是 bigint 类型。
      

  10.   

    update tb set
        name = stuff(name,1,2,'');
      

  11.   

    DECLARE @T TABLE (ID INT,NAME VARCHAR(10))
    INSERT INTO @T
    SELECT 1,'p_lihao' UNION ALL
    SELECT 2,'p_caitou' UNION ALL
    SELECT 3,'p_xiaoming' UNION AL
    update @T set
        name = stuff(name,1,2,'')
    where name like 'p$_%' escape '$';select * from @T
      

  12.   


    update tb set name = replace(name,'p_','')
      

  13.   

             1.update yourtable set name = substring([name],charindex('p_',name)+2,len(name));         2.update yourtable set name = stuff(name,1,2,'');         3.update yourtable set name = replace(name,'p_','') 上面的三种方法都可以实现
      

  14.   

    stuff(name,1,2,'') 和 replace(name,'p_','')
    是不是都在开头有空格了啊。
    那还是第一种号一点啊,直接截取
      

  15.   

    update tb set NAME=substring(NAME,charindex('_',NAME)+1,len(NAME)-charindex('_',NAME))