表  a   有一个 c 的字段。  里面存的是一个路径。 我现在要在图片名字前加上 “s_“  不知道怎么加
/ojuju_img/floorplanner/householdpic/4396.png变成:/ojuju_img/floorplanner/householdpic/s_4396.png
如果字段是空或者没有 后缀(.png) 说明这条数据无效。不要动他。
希望各位高手帮忙

解决方案 »

  1.   


    update tb 
    set 字段c = reverse(stuff(reverse(字段c),charindex('/',reverse(字段c)),1,'_s/'))
    where 字段c is not null and charindex('.png',字段c)>0
      

  2.   

    开阔一下思路,
    可以用uda函数,即用.net语言写的函数添加到相应的数据库(sql server2005才支持),在sql 语句中调用
      

  3.   

    如果数据是  123.png 的话,执行语句后就变成 null 了。 能不能再帮我解决这个bug 啊。  
      

  4.   

    试试这个declare @a table(c nvarchar(100))
    insert into @a
    select '/ojuju_img/floorplanner/householdpic/123.png' union all
    select '/ojuju_img/floorplanner/householdpic/456.png' union all
    select '/ojuju_img/floorplanner/householdpic/789.jpg' union all
    select '' union all
    select null 
    update @a set c = stuff(c,len(c) - charindex('/',reverse(c)) + 2,0,'s_')
        where c is not null and charindex('.png',c)>0select * from @a
      

  5.   


    (5 行受影响)(2 行受影响)
    c
    ----------------------------------------------------------------------------------------------------
    /ojuju_img/floorplanner/householdpic/s_123.png
    /ojuju_img/floorplanner/householdpic/s_456.png
    /ojuju_img/floorplanner/householdpic/789.jpgNULL(5 行受影响)
      

  6.   


    --建表---------------------------------------------
    create table Data
    (
    [path] nvarchar(100)
    )
    --测试数据----------------------------------
    insert into Data
    values('/ojuju_img/floorplanner/householdpic/4396.png')
    --sql语句----------------------------------
    update Data
    set [path]= reverse(stuff(reverse([path]),charindex('/',reverse([path])),0,'_s'))
    --结果----------------------------------------
    /*path
    -----
    /ojuju_img/floorplanner/householdpic/s_4396.png*/
      

  7.   

    --建表---------------------------------------------
    create table Data
    (
        [path] nvarchar(100)
    )
    --测试数据----------------------------------
    insert into Data
    values('/ojuju_img/floorplanner/householdpic/4396.png')
    --sql语句----------------------------------
    update Data
    set [path]= reverse(stuff(reverse([path]),charindex('/',reverse([path])),0,'_s'))
    where [path] like '%.png' 
    --结果----------------------------------------
    /*path
    -----
    /ojuju_img/floorplanner/householdpic/s_4396.png*/