SELECT – Like

This statement searches for and returns all fields that contain a pattern similar to the pattern specified.

Syntax

match_expression [NOT] LIKE pattern

Parameters

match_expression

Specifies the SQL Server expression to compare with the pattern. This expression must be of string data type.

pattern

Specifies the pattern to search for in the match_expression parameter and can contain the percent character (%) as a wildcard.

escape_character

Specifies the character string to use as an escape character. There is no default character for escape_character and it must contain only one character.

Remarks

The percent wildcard character (%) can be used to search for a string using one of three patterns:

Type of Search Wildcard Pattern
String begins with "type" LIKE 'type%'
String contains "type" LIKE '%type%'
String ends with "type" LIKE '%type'

Prior to version 2.12, ADO for Windows CE did not allow for a query of the literal percent character (%) at the beginning or end of a string.

Constructing a statement with the wildcard character embedded in the statement ('sam%le') results in the string being matched literally.

Example

The following code example shows how to use a SQL statement to search for the string, "10%." The data is displayed in a ListBox named List1.

Dim rs, i
Set rs = CreateObject("adoce.recordset")
rs.open "SELECT col1 FROM myTable WHERE col1 LIKE '10\%'" , "", 1, 3
If rs.RecordCount > 0 Then
  Do While Not rs.EOF
    List1.AddItem rs.fields("firstfield").Value
    rs.MoveNext
  Loop
End If
rs.Close
Set rs = Nothing