T-SQL, Part I: LIKE Pattern
2016-03-27 15:06
337 查看
The basic usage of LIKE pattern:
%: it would be placed at the end and/or the beginning of a string.
_: it looks at a string, but only for a single character before or after the position of the underscore.
[]: it lets you specify a number of values or a range of values to look for. For example: “%[c-f]%”.
[^…]: Similar to [] option, it lists those items that do not have values within the range specified.
However, consider the question ‘Combination of ‘LIKE’ and ‘IN’ using t-sql’ raised in Stackoverflow: http://stackoverflow.com/questions/6102380/combination-of-like-and-in-using-t-sql
Question:
Or more generic one:
To solve the real question, the following scripts helps:
To solve the generic question, the following scripts helps:
是为之记。
Alva Chien
2016.3.23
%: it would be placed at the end and/or the beginning of a string.
_: it looks at a string, but only for a single character before or after the position of the underscore.
[]: it lets you specify a number of values or a range of values to look for. For example: “%[c-f]%”.
[^…]: Similar to [] option, it lists those items that do not have values within the range specified.
However, consider the question ‘Combination of ‘LIKE’ and ‘IN’ using t-sql’ raised in Stackoverflow: http://stackoverflow.com/questions/6102380/combination-of-like-and-in-using-t-sql
Question:
SELECT * FROM Street Where StreetName LIKE IN (SELECT name + ‘%’ from CarStreets Where Streets = ‘offroad’ )
Or more generic one:
SELECT * FROM Street WHERE StreetName LIKE IN (‘% Main Street’, ‘foo %’)
To solve the real question, the following scripts helps:
SELECT DISTINCT s.* FROM Street s JOIN CarStreets cs ON s.StreetName LIKE cs.name + ‘%’ WHERE cs.Streets = ‘offroad’
To solve the generic question, the following scripts helps:
WITH Query(Result) As ( SELECT ‘% Main Street’ UNION ALL SELECT ‘foo %’ ) SELECT DISTINCT s.* FROM Street s JOIN Query q ON StreetName LIKE q.Result;
是为之记。
Alva Chien
2016.3.23
相关文章推荐
- 第57课:SparkSQL案例实战学习笔记
- 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)
- MYSQL的常用命令和增删改查语句和数据类型
- 通过ServletConfig加载web.xml文件来连接数据库
- Oracle:高效插入大量数据经验之谈
- [go] database/sql包执行生成的SQL语句,遇到Incorrect Integer错误
- Bison executable not found in PATH by mysql install
- SQL Server 2012 实现分页新语法
- SQl优化问题4
- SQl优化问题3
- SQl优化问题2
- SQL 优化问题1
- oracle默认排序
- sql service 游标和触发器的使用
- 数据库_chapter05
- mysql5.6.28 备份主要参数学习
- sql server 向oracle导入表
- 向sql server 导入数据库
- mysql优化 之 表设计注意事项
- 数据库批量修改表名,增加前缀(SQL server)