有一个表 有个content 字段
当添加数据时如何过滤一些脏字
写出几个脏字来'Fuck,sb'等等
能不能做到精确过滤或是模糊过滤
可能写出以上两种方案吗?

解决方案 »

  1.   

    用一個表記錄脏字插入時判斷 if  exists(select 1 from 記錄表 where [Text]=@插入參數)
      

  2.   

    charindex(',Fuck,' , ','+col+',') > 0
    charindex(',sb,' , ','+col+',') > 0
      

  3.   

    if object_id('ta')is not null drop table ta
    go
    create table ta (ID int identity(1,1),content varchar(15))--脏字表
    insert ta(content) select 'Fuck'
    insert ta(content) select 'SB'
    insert ta(content) select '操你'
    insert ta(content) select '日'
    if object_id('tb')is not null drop table tb
    go
    create table tb (ID int identity(1,1),content varchar(15))--正常表
    declare @str varchar(20)
    declare @str2 varchar(20)
    set @str2='你好'
    set @str='Fuck you'
    insert tb(content) select @str where not exists(select 1 from ta a where charindex(''+a.content+'',@str)>0 )
    insert tb(content) select @str2 where not exists(select 1 from ta a where charindex(''+a.content+'',@str2)>0 )
    select * from tb
    /*
    ID          content         
    ----------- --------------- 
    1           你好
    */
      

  4.   

    declare @str Nvarchar(4000)
    set @str=',Fuck,SB,'
    --select * from guolv where charindex(','+content+',',','+@str+',')>0select * from biao where charindex(content,@str)>0