Escape single quotes and wild cards ‘%’ , ‘_’ in MS SQL
来源:互联网 发布:梁边妖 知乎 编辑:程序博客网 时间:2024/05/30 05:08
To escape single quotes ( ‘ ) in MS SQL all you need to do is add two single quotes instead of one.
Ex. If you want to insert the name D’souza into MS SQL the query goes like this:
INSERT into name_column ([name]) VALUES (‘D”Souza’)
Look carefully. We have replaced single quote in between the letter D and the word SOUZA with twoSINGLE QUOTES. (It’s not a double quote)
Similarly, you may also face a problem while querying for values which contain the characters ‘%’ and ‘_’ in them. This is so because SQL considers these two characters as wild cards for multiple characters and single character string matching.
There are 2 ways to escape these wild cards.
1. You can use the default square braces “[]” like this- [%] or [_]
2. You can define your own escape character by using thekeyword ESCAPE at the end of your where clause.
Ex. select * from name_column where name like ‘gyan\_sagar’ ESCAPE ‘\’
In the example above we escape “_” by defining “\” as an escape character using the ESCAPE keyword.
Note: You can only define a single character for escaping andnot a string.
- Escape single quotes and wild cards ‘%’ , ‘_’ in MS SQL
- Escape both single quote and double quote in Smarty
- Linux - Wild cards
- sql like 通配符 % _ escape
- Single quotes, among other characters that are not supported in PeopleTools Run Control Ids
- Error in DB connect for DB2, DB4 and MS-SQL-Server
- printf and wprintf in single C code
- High-Fidelity Pose and Expression Normalization for Face Recognition in the Wild
- Breakout detection in the wild
- Breakout detection in the wild
- Breakout detection in the wild
- SQL模糊查询%_^[]和Escape转义字符
- sql escape
- Insert, Update, Delete in ASP.NET Gridview, DataSource as SQL Server, MS Access (mdb/accdb), XML and
- Previewing and plotting a single sheet in AutoCAD using .NET
- SQL Interview Preparation (in the context of MS SQL Server)
- in the cards 稳操胜券
- A. Vanya and Cards
- dll和lib的区别
- 时髦的开发者=潮流的应用
- 多线程类
- Linux内核编程(项目笔记)——项目:创建并口驱动程序
- 写了一个简单的带有CheckBox的Tree[Swing]
- Escape single quotes and wild cards ‘%’ , ‘_’ in MS SQL
- GCC后端及汇编发布(37)
- GCC's bacl-end & assemble emission (37)
- GCC后端及汇编发布(38)
- GCC's bacl-end & assemble emission (38)
- Blob、InputStream、byte 互转
- 百度对site语法的几种情况
- SQL Server 转义字符序列 like escape的使用方法
- 数据库6范式