Friday, 16 March 2018

sql server - TSQL Query: Escaping Special Characters



I am trying to escape special characters in a TSQL query. I have done this before:



SELECT columns FROM table WHERE column LIKE '%\%%' ESCAPE '\'


And it has worked. Now I have tried to do this now:



UPDATE match SET rule_name='31' ESCAPE '\'


But it has failed. I know none of the vlaues have a \ but it should still work. I am guessing its because it needs a LIKE statement but how else can I escape characters that I am adding to a database?



In addition, does anyone have a link to all the special characters that should be escaped, I couldn't find any documentation on this!



Thanks all for any help


Answer



The documentation for the LIKE clause has a list of characters that require escaping.



ESCAPE is only defined as part of the LIKE clause, which is why your second query fails (no LIKE clause).


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...