字段 Code :S00-0100001
           S00-1200045
           S00-JA01324
           S00-GD00221
现要在Code字段中插入年份:10
得到结果:S00-011000001
          S00-121000045
          S00-JA1001324
          S00-GD1000221
如何写这个SQL,谢谢了!

解决方案 »

  1.   

    update ta
    set code = left(code,6)+'10'+right(code,5)
      

  2.   

    本帖最后由 roy_88 于 2010-01-22 11:32:47 编辑
      

  3.   

    update tb
    set code=left(code,6)+'10'+right(code,len(code)-6)
      

  4.   

    本帖最后由 roy_88 于 2010-01-22 11:33:43 编辑
      

  5.   


    --> 测试数据: #t
    if object_id('tempdb.dbo.#t') is not null drop table #t
    go
    create table #t (Code varchar(11))
    insert into #t
    select 'S00-0100001' union all
    select 'S00-1200045' union all
    select 'S00-JA01324' union all
    select 'S00-GD00221'
    declare @str varchar(30)
    set @str = '10'select left(code,6)+@str+right(code,6) 
    from #t---------------------------------------------------- 
    S00-0110100001
    S00-1210200045
    S00-JA10A01324
    S00-GD10D00221(所影响的行数为 4 行)
      

  6.   

    update ta 
    set code = replace(Code ,'S00-','S00-10')
      

  7.   

    update
     tb
    set
     code=left(code,6)+'10'+right(code,len(code)-6)