Select Stuff(N'某些人(254)的年龄大于50',CharIndex('(',N'某些人(254)的年龄大于50'),CharIndex(')',N'某些人(254)的年龄大于50')-CharIndex('(',N'某些人(254)的年龄大于50')+1,'')

解决方案 »

  1.   

    N是unicode,防止你的中文出现乱码的。
      

  2.   

    奇怪,出错了SELECT STUFF('(123)字符截错了',2,1,'')结果怎么为:(23)字符
      

  3.   


    SELECT STUFF(N'(123)字符截错了',2,1,'')
    的结果是(23)字符截错了
    SELECT STUFF(N'(123)字符截错了',1,5,'')
    得到的结果才是   字符截错了
      

  4.   

    唉,对了我刚刚是在另外一个数据库上试的,不对我现在是在MSSQL上试了,正确
      

  5.   

    while charindex('(',@s,1)>0 and charindex(')',@s,1)>0
    begin
    select @s=replace(@s,substring(@s,charindex('(',@s,1),charindex(')',@s,1)-charindex('(',@s,1)+1),'')
    end
    select @s
      

  6.   

    declare @s nvarchar(4000)
    set @s='某些人(254)的年龄大于50'while charindex('(',@s,1)>0 and charindex(')',@s,1)>0
    begin
    select @s=replace(@s,substring(@s,charindex('(',@s,1),charindex(')',@s,1)-charindex('(',@s,1)+1),'')
    end
    select @s