我想在一数据库表news的字段content中的前2000个字符后加入一“|!---page split---|”字符(如果这个字段之前已经含有这个字符就不再增加了。这个sql应该怎么写?谢谢各位。

解决方案 »

  1.   

    update a 
    set 
        content=stuff(a.content,2000,0,'|!---page split---|') 
    from 
        news a
    where 
        left(a.content,2000) not like '%|!---page split---|%'
      

  2.   

    update news set content=STUFF(content,2000-len('|!---page split---|'),0,'|!---page split---|')
    where CHARINDEX('|!---page split---|',content)=0
      

  3.   

    update a 
    set 
        content=stuff(a.content,2000,0,'|!---page split---|') 
    from 
        news a
    where 
        a.content not like '%|!---page split---|%'
      

  4.   

    上面都是通过加后缀来实现的```我用追加字符串也可以实现的:
    update temp set content=content +'|!---page split---|' where right(content,23) != '|!---page split---|'