LIKE (SQL Server Compact Edition)

Determines whether a given character string matches a specified pattern. A pattern can include regular characters and wildcard characters. During pattern matching, regular characters must match exactly the characters specified in the character string. Wildcard characters, however, can be matched with arbitrary fragments of the character string. Using wildcard characters makes the LIKE operator more flexible than using the = and != string comparison operators. If any of the arguments are not of a character string data type, Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) converts them to a character string data type, if possible.

Syntax

match_expression [ NOT ] LIKE pattern [ ESCAPE escape_character ] 

Arguments

  • match_expression
    Any valid expression in SQL Server Compact Edition of nchar, nvarchar, or ntext data type.
  • pattern
    The pattern to search for in match_expression. It can include the following valid SQL Server Compact Edition wildcard characters:

    Wildcard character Description Example

    %

    Any string of zero or more characters.

    WHERE title LIKE '%computer%' finds all book titles with the word 'computer' anywhere in the book title.

    _ (underscore)

    Any single character.

    WHERE au_fname LIKE '_ean' finds all four-letter first names that end with ean, such as Dean or Sean.

  • escape_character
    Any valid expression in SQL Server Compact Edition of any of the data types of the character string data type category. The escape_character argument has no default and must consist of only one character.

Result Types

bit

Return Value

LIKE returns TRUE if the match_expression matches the specified pattern.

Remarks

If you are comparing an exact string without any wildcard characters, you should use = or != instead of LIKE. When using LIKE, SQL Server Compact Edition does not add additional padding to your match expression, and so queries against fixed-size columns will fail. If you use = or !=, the padding is automatically added.

See Also

Reference

= (Equals) (SQL Server Compact Edition)
!= (Not Equal To) (SQL Server Compact Edition)

Help and Information

Getting SQL Server Compact Edition Assistance