Like
Determines whether the specified string matches the specified pattern. The mode can contain regular and wildcard characters. During pattern matching, regular characters must match exactly the characters specified in the string. However, any part of a string can be used to match a wildcard. And use=And! =Use wildcards to enableLikeMore flexible operators.
If no parameter belongs to the string data typeSQLServerIt is converted to the string data type (if possible ).
Syntax
Match_expression_r_r[Not]LikePattern[EscapeEscape_character]
Parameters
Match_expression_r_r
Valid for any string data typeSQLServerExpression.
Pattern
Match_expression_r_rCan contain the following valid search modes:SQLServerWildcard.
WildcardDescriptionExample
%Any string containing zero or more characters.WhereTitleLike'% Computer %'Searches for words in any position of the title.Computer.
_ (Underline)Any single character.WhereAu_fnameLike'_ Eany'EANAll4Letter names (Dean, Sean).
[]Specified range([A-f])Or set([Abcdef])Any single character in.WhereAu_lnameLike'[C-P] arsen'Will look up with arsenEndCAndPThe last name of the author starting from any single character, such as Carsen, Larsen, and Karsen..
[^]Does not belong to the specified range([A-f])Or set([Abcdef])Any single character.WhereAu_lnameLike'De [^ L] %'DeThe START Letter and the suffix letter is notLThe surname of all authors.
Escape_character
Any valid value for all data types in string data type classificationSQLServerExpression. Escape_characterNo Default Value and must contain only one character.
Result type
Boolean
Result Value
IfMatch_expression_r_rMatches the specified mode, likeReturnsTrue.
Note
When usingLikeWhen comparing strings, All characters in the mode string are meaningful, including start or trailing spaces. If the comparison in the query contains "ABC ","(ABCIf there is a space in the left-side navigation pane.The row where the column is located. However, trailing spaces in the expression to be matched by the pattern can be ignored. If the comparison in the query contains "ABC" (ABCAll rows that start with "ABC" and have zero or multiple trailing spaces.
For data storageCharAndVarcharStrings in the data mode may fail to passLikeComparison. Understand the storage methods of each data type andLikeThe cause of the comparison failure is very important. In the following exampleCharVariables are passed to the stored procedure, and then all the books of an author are searched using pattern matching. In this process, the author's surname is passed as a variable.
when the number of characters in the name is less than 20 , the char variable (@ au_lname) contains trailing spaces, which causes no rows to be returned during find_books . Because the au_lname column is of the varchar type, no trailing space is required. This process fails because trailing spaces are meaningful.