t1表中有一字段 a
a(列名)
123/234234
123/afsdf
123/oi23#
123/89324
123/@#$
123/2323
想在表内容改成
a(列名)
1234/234234
1234/afsdf
1234/oi23#
1234/89324
1234/@#$
1234/2323就是"/"前面的123改成1234 "/"后面的数据不变求此sql语句

解决方案 »

  1.   


      这是SQL里面字符串截取,去baidu找下先关函数`!
      

  2.   

    REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )
      

  3.   

    光取出来 不行呀 还要保存到数据库中....
    replace(a,'123','1234')
    这个不行啊
      

  4.   

    REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )
      

  5.   

    update t1 set bbb=stuff(bbb,0,3,'1234')
    我是这么写的 但是不知道哪里有错误 执行后结果全是null
      

  6.   


    declare @t table(s varchar(50))
    insert into @t select '123/234234'
    union all select '123/afsdf'
    union all select '123/oi23#'
    union all select '123/89324'
    union all select '123/@#$'
    union all select '123/2323'update @t set s=replace(s,'123','1234')
    select * from @t
      

  7.   

    ---------------结果----------------
    1234/234234
    1234/afsdf
    1234/oi23#
    1234/89324
    1234/@#$
    1234/2323
      

  8.   

    数据库里有上W条数据...
    要是这么写...得写到下个世纪
    declare @t table(s varchar(50))
    insert into @t select '123/234234'
    union all select '123/afsdf'
    union all select '123/oi23#'
    union all select '123/89324'
    union all select '123/@#$'
    union all select '123/2323'update @t set s=replace(s,'123','1234')
    select * from @t
      

  9.   

    奇怪为什么不行啊,你不是字段a吗?update tablename
    set a = Replace(a,'123','1234')
    不久可以了吗
      

  10.   

    我只是测试,你直接update @t set s=replace(s,'123','1234')不就行了..
      

  11.   

    string strHref = a;
    int intPos = strHref.IndexOf("/");
    string strRight = strHref.Substring(intPos + 1);
    a="1234/"+strRight;
      

  12.   

    UPDATE [t1]
       SET [bbb] = stuff([bbb],1,3,'1234')
      

  13.   

    个人觉得replace不安全update t1 set a=left(a,3) + '4' + right(a,len(a)-3)
      

  14.   

    update tb_1 set tb_name=stuff(tb_name,1,3,'1234')
    or
    update tb_1 set tb_name=replace(tb_name,'123','1234')
      

  15.   

    declare @t table(id int identity ,s varchar(50))
    insert into @t(s) select '123/234234'
    union all select '123/afsdf'
    union all select '123/oi23#'
    union all select '123/89324'
    union all select '123/@#$'
    union all select '123/2323'
    declare @aString varchar(100),@i int,@id int,@str varchar(100)
        
    declare cus cursor for
    select * from @t
    open cus
    fetch next from cus into @id,@aString
    while @@fetch_status=0
    begin
    set @aString=rtrim(ltrim(@aString))
    set @i=charindex('/',@aString)
    if(@i>0)
    begin
    set @str=left(@aString,@i-1)
    update @t set s=replace(@str,'123','1234')+right(@aString,len(@aString)-@i+1) where [id]=@id
    end
    fetch next from cus into  @id,@aString
    end
    deallocate cusselect * from @t
      

  16.   

    我用这种方法解决的
    update tb_1 set tb_name=stuff(tb_name,1,3,'1234')非常感谢大家的答复 因为...问题不是很难..所以分没给的太高...下次遇到难的问题...给高分..呵呵 分给的太低..有点惭愧...
      

  17.   

    update table set a=stuffc(a,1,3,'1234')
      

  18.   

    update t1 set a=replace(a,'/','4/')
      

  19.   

    update t1 set a = replace(a,'123/','1234/')
    觉得这样方便,而且万一/后也有123,就不会把后面的也替换了。