id title
1  2012星光大道:张三
2  2012星光大道:李四
3  2013星光大道:王五
求个sql语句
把title包含 2012星光大道 替换为 2014星光大道
要的结果是id title
1  2014星光大道:张三
2  2014星光大道:李四
3  2013星光大道:王五

解决方案 »

  1.   


    --> 测试数据:[tbl]
    if object_id('[tbl]') is not null drop table [tbl]
    create table [tbl]([id] int,[title] varchar(17))
    insert [tbl]
    select 1,'2012星光大道:张三' union all
    select 2,'2012星光大道:李四' union all
    select 3,'2013星光大道:王五'update tbl
    set [title]=REPLACE([title],'2012','2014') where 
    CHARINDEX('2012星光大道',[title])>0select * from tbl/*
    id title
    1 2014星光大道:张三
    2 2014星光大道:李四
    3 2013星光大道:王五
    */
      

  2.   

    update table set title = replace(title,'2012星光大道','2014星光大道') where title like '2012星光大道%'