MSSQL中Escape转义的使用

IF OBJECT_ID('tempdb..#ABC') is not null
drop table tempdb..#ABC


create table #ABC
(
PATHNAME NVARCHAR(50)
)


insert into #ABC
SELECT N'/ABCDEFGHI' 
UNION ALL SELECT N'/ABCDGAFGASASSDFA' 
UNION ALL SELECT N'/ABCD' 
UNION ALL SELECT N'/ABCD/' 
UNION ALL SELECT N'/ABCD/JINJI' 
UNION ALL SELECT N'/ABCD/JINJI/MMMNNNN'
UNION ALL SELECT N'XXXX/ABCD/JINJI/MMMNNNN'


----查看PATHNAME中包含/ABCD/的记录
SELECT * FROM #ABC
WHERE PATHNAME LIKE N'%//ABCD//%' escape '/'

查询结果

PATHNAME
--------------------------------------------------
/ABCD/
/ABCD/JINJI
/ABCD/JINJI/MMMNNNN
XXXX/ABCD/JINJI/MMMNNNN



你可能感兴趣的:(MSSQL)