This question already has an answer here:
这个问题在这里已有答案:
- How do I escape a percentage sign in T-SQL? 3 answers
如何在T-SQL中转义百分号? 3个答案
I have a record with a value Jacj%25011987
. I wanted to search the record with %
as a character in a string.
我有一个值为Jacj%25011987的记录。我想用%作为字符串中的字符来搜索记录。
I wanted to search this record using the Like
in where
clause.
我想使用Like in where子句搜索此记录。
I tried these queries, but they didn't work:
我尝试了这些查询,但它们不起作用:
Select *
From Table1 With (Nolock)
Where Column1 like '%\%%'
Select *
From Table1 With (Nolock)
Where Column1 like '%'%%'
Thanks Parag
1 个解决方案
#1
11
I think the easiest way is to use []
:
我认为最简单的方法是使用[]:
where column1 like '%[%]%'
You can also use escape
with whatever you like for the escape character:
你也可以使用escape来解决转义字符:
where column1 like '%!%%' escape '!'
This is more portable, because ESCAPE
is part of the ANSI standard.
这更便携,因为ESCAPE是ANSI标准的一部分。
#1
11
I think the easiest way is to use []
:
我认为最简单的方法是使用[]:
where column1 like '%[%]%'
You can also use escape
with whatever you like for the escape character:
你也可以使用escape来解决转义字符:
where column1 like '%!%%' escape '!'
This is more portable, because ESCAPE
is part of the ANSI standard.
这更便携,因为ESCAPE是ANSI标准的一部分。