LIKE predicate page 2
LIKE predicate and regular expressions
LIKE predicate in its standard edition does not support regular expressions, though a number of implementations (in particular, Oracle) supposes their usage, expanding the standard.
In A database management system (DBMS) by Microsoft Corporation. SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL Server 2005/2008, the use of regular expressions is possible through CLR, i.e. by means of Visual Studio languages which can be used for writing stored procedures and UDFs.
However, Transact-SQL, besides standard wildcard characters ("%" and "_"), introduces pair of additional symbols which make LIKE predicate more flexible as a tool. These symbols are:
Let's explain use of these symbols by examples.
In the given query some data are generated, for search over which the LIKE predicate is used. Nine examples is accordingly 9 commented (--) WHERE clauses. For check of results of executing of above query on the site, erase preliminary the comment for one of the lines beginning with WHERE. For those who cannot use a site, I shall present the results of executing these examples below.
1. All the strings, which begin with 5:
2. Searching of the string '5%'. The character in brackets is perceived as a usual single symbol:
3.Other solution which is similar to the second one, but it is using the ESCAPE clause, specifying that it is necessary to perceive "%" as an usual symbol.
4. Searching of the substring '5%' being at any place in the string:
5. Searching of a string in which the first symbol is a digit, but the second one is a letter:
6. Searching of a string in which the first symbol is a letter, and the second one is a digit. A variant for case-independent comparisons:
7. Searching of a string which begins not with digit:
8. Searching of a string which contains even digit:
9. Searching of a string which contains successively going even and odd digits: