SQL Wave Char

Today, My colleague asked me a question that Entity Framework will generate SQL and has ESCAPE '~' at the end of the SQL.

SELECT * FROM T WHERE Title LIKE 'foo%' ESCAPE '~'

After the survey, some of the article that the only things we knew it is ESCAPE are used to query the data has  Universal characters.There are no articles about "~".Through some of the testing, we found it represented all of the Universal characters.Which means you may be used ESCAPE '%_[^' to query has the data include it then you can just use ESCAPE '~' to replace it.
SELECT * FROM T WHERE Title LIKE 'foo%' ESCAPE '%_[]^'
equal
SELECT * FROM T WHERE Title LIKE 'foo%' ESCAPE '~'


The char "~"  represented all of the Universal characters.If we want to query the data has "~" that could be work?
SELECT * FROM T WHERE (Title LIKE '~%' ESCAPE '%_[]^')
result:Cannot be query

Modify SQL,Replace"~" to "~~"
SELECT * FROM T WHERE (Title LIKE '~~%' ESCAPE '%_[]^')
result:OK

Ps: When Entity Framework is querying that will auto detecting if it has "~" or not, it will be replaced to two "~" while finding it.
This function is so convenient, isn't it?

Reference

Popular posts from this blog

Stopping TypeScript Compile to accelerate debugging

VS2017 Unable to copy file roslyn