#$为开始符号 $#为结束符号
id content
1 #$aaaa$#
2 #aaaa$#
3 aaa#$aaaa$#aaaaaa如果记录中有有符号不匹配,就返回这个记录
上面返回结果是
id content
2 #aaaa$#
id content
1 #$aaaa$#
2 #aaaa$#
3 aaa#$aaaa$#aaaaaa如果记录中有有符号不匹配,就返回这个记录
上面返回结果是
id content
2 #aaaa$#
select * from tbName A
where not exists(select 1 from tbName where charindex(A.content, content)>0 and A.content<>content)
select * from tablename where charindex('$#',content)>charindex('#$',content)
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)
Where CharIndex('#$',content) <= 0
Or CharIndex('$#', content, CharIndex('#$',content) +1) <= 0
(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$#
*/
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$#