create table #(a varchar(20)) insert into # select '15%'select * from # where a='15%'可以阿
select * from tablename where column like '%15[%]%'
那再加一个不就行了? select * from # where a like '15%%'
TO:jacobsan(梅) 这样会把包含15的数据也查询出来
select * from ( select col='15' union all select '%15%' union all select '%15' union all select '15%' ) a where a.col='15%'--result col ---- 15%(1 row(s) affected)
例子: select * from tablename where column like '%[%]%' --这样就可以找出某一列中含有'%'的行了用中括号‘[]’把‘%’扩起来就认为是普通字符了
为什么不用charindex()函数呢?select * from # where charindex('15%',a)>0
select * from ( select col='15' union all select '%15%' union all select '%15' union all select '15%' ) a where a.col like '%[%]%'
select * from a where [name] like '%15[%]%' select * from A where charindex('15%',[name])>0 对
使用 ESCAPE 关键字定义转义符。在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。例如,要搜索在任意位置包含字符串 5% 的字符串,请使用: WHERE ColumnA LIKE '15/%%' ESCAPE '/'
使用 ESCAPE 关键字定义转义符。在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。例如,要搜索在任意位置包含字符串 15% 的字符串,请使用: WHERE ColumnA LIKE '%15/%%' ESCAPE '/'
insert into # select '15%'select * from # where a='15%'可以阿
select * from # where a like '15%%'
这样会把包含15的数据也查询出来
select * from
(
select col='15'
union all select '%15%'
union all select '%15'
union all select '15%'
) a
where a.col='15%'--result
col
----
15%(1 row(s) affected)
select * from
(
select col='15'
union all select '%15%'
union all select '%15'
union all select '15%'
) a
where a.col like '%[%]%'
select * from A where charindex('15%',[name])>0 对
WHERE ColumnA LIKE '15/%%' ESCAPE '/'
WHERE ColumnA LIKE '%15/%%' ESCAPE '/'