一个SQL语句问题,我的一个字段里面有% 和_ 我怎么才能够查出来呢?以前我一直用
CString str ;
str.format(select * from biao where ziduan like '%%s%%', name);
可是当name 是% 和_ 就显示所有结果了 我该怎么查
CString str ;
str.format(select * from biao where ziduan like '%%s%%', name);
可是当name 是% 和_ 就显示所有结果了 我该怎么查
insert into tb select 'fdfasf'select * from tb where col like '%b\%%' escape '\'
drop table tb
insert into tb select 'fdfasf'
insert into tb select 'fdf%_fdf'select * from tb where col like '%b\%%' escape '\'/*
col
--------
ab%bb
*/select * from tb where col like '%\%_%' escape '\'
/*
col
--------
ab%bb
fdf%_fdf
*/drop table tb
go
insert into tb select 'ab%bb'
insert into tb select 'fdfasf'select * from tb where col like '%b\%%' escape '\'select * from tb where col like '%b[%]%'
godrop table tb
go
col
--------------------
ab%bb
fdfasf
fdf%_fdf
fdbf%_fdf
fdbfb%_fdf
fdfbasf
fdbfb%h_fdf(所影响的行数为 7 行)select * from tb where col like '%[%]h%'
col
--------------------
fdbfb%h_fdf(所影响的行数为 1 行)
create table tb (col varchar(20))insert into tb select 'ab%bb'
insert into tb select 'fdfasf'
insert into tb select 'fdf%_fdf'
insert into tb select 'fd'''
insert into tb select 'fd''fdfdasf'select * from tb where col like '%d\''%' escape '\'/*
col
--------
fd'
fd'fdfdasf
*/
drop table tb
"C:\\Documents and Settings\\guest\\桌面" 这是对后面的\进行转义
[转]:http://topic.csdn.net/t/20050916/13/4275000.html
1.两个双引号相当于一个单引号
select ''''
2.like中可以用escape转义
SELECT notes
FROM titles
WHERE notes LIKE '50%% off when 100 or more copies are purchased'
ESCAPE '%'
(
col varchar(20)
)
goinsert into #t select 'ab%bb'
insert into #t select 'fdfasf'select * from #t where col like '%b\%%' escape '\'select * from #t where col like '%b[%]%'
godrop table #t
go
insert into tb select 'fdfasf'select * from tb where col like '%b\%%' escape '\'
drop table tb