-1

I have a series of questions in a table, I want all the records that contain the word size and must end with a "?" in the record. When I do a SQL, the "?" is treated as a special character but I want it treated it as a normal character, how do I escape it. I've looked on the internet and StackOverflow but the only questions explain that "?" is a wild card which I don't want it to be.

select * from Questions where QuestionText like '%Size%?'

So it returns for example... Its simplistic but you get the idea hopefully.

What is the size of france?

But doesn't return

What is the size of france.
Dale K
  • 25,246
  • 15
  • 42
  • 71
MiscellaneousUser
  • 2,915
  • 4
  • 25
  • 44
  • Does this answer your question? [How can I escape square brackets in a LIKE clause?](https://stackoverflow.com/questions/439495/how-can-i-escape-square-brackets-in-a-like-clause) – Charlieface Mar 16 '21 at 19:51
  • 1
    I’m voting to close this question because the behavior is documented: [Pattern Matching with the ESCAPE Clause](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/like-transact-sql?view=sql-server-ver15#pattern-matching-with-the-escape-clause). – HABO Mar 16 '21 at 20:14

1 Answers1

0

To escape the special meaning of any special character, just enclose it in square brackets.

Select * from Questions where QuestionText like '%Size%[?]'
Pradeep Kumar
  • 6,836
  • 4
  • 21
  • 47