#$为开始符号 $#为结束符号
id           content
1            #$aaaa$#
2            #aaaa$#
3            aaa#$aaaa$#aaaaaa如果记录中有有符号不匹配,就返回这个记录
上面返回结果是
id           content
2            #aaaa$#

解决方案 »

  1.   


    select * from tbName A
    where not exists(select 1 from tbName where charindex(A.content, content)>0 and A.content<>content)
      

  2.   

    ---try
    select * from tablename where charindex('$#',content)>charindex('#$',content)
      

  3.   


    create table T(id int, content varchar(50))
    insert T select 1,            '#$aaaa$#'
    union all select 2,            '#aaaa$#'
    union all select 3,            'aaa#$aaaa$#aaaaaa'
    select * from T A
    where (select count(*) from T where charindex(A.content, content)>0 or charindex(content, A.content)>0)=1--result
    id          content                                            
    ----------- -------------------------------------------------- 
    2           #aaaa$#(1 row(s) affected)
      

  4.   

    Select * From TEST A
    Where CharIndex('#$',content) <= 0 
    Or CharIndex('$#', content, CharIndex('#$',content) +1) <= 0
      

  5.   

    Create Table TEST
    (id Int,
     content Varchar(100))
    Insert TEST Select 1,            '#$aaaa$#'
    Union All Select 2,            '#aaaa$#'
    Union All Select 3,            'aaa#$aaaa$#aaaaaa'
    GO
    Select * From TEST A
    Where CharIndex('#$',content) <= 0 Or CharIndex('$#', content, CharIndex('#$',content) +1) <= 0
    GO
    Drop Table TEST
    --Result
    /*
    id content
    2 #aaaa$#
    */
      

  6.   

    这样不可以么
    create table #temp
    (id int,
    content varchar(50)
    )
    insert into #temp
    select '1','#$aaaa$#' union all 
    select '2','#aaaa$#' union all 
    select '3','aaa#$aaaa$#aaaaaa'
    select * from #temp where content not like '%#$%$#%'------------
    2 #aaaa$#
      

  7.   

    select * from #temp where patindex('%#$%$#%',content)=0
      

  8.   

    select * from t where col not like '%#$%$#%'