SQL Server Like keyword is use with where condition to extend the filter.
Like keyword searches the result in below patterns.
SQL Server use the following character with Like keyword to search result in result set.
1) '_' (Underscore) - It represents a one character in table data.
2) '%' (Percent) - It represents more than one character in table data.
3) [] (wildcard) - It represent list of single character in table data.
We can use above all operator at same time with each other.
Let consider below list of shopping items and we are going to apply Like keyword in this table.
1) 'L_ _' - List all product whose first character is L and total length is 3.
2) 'L_D' - List all product whose first character is L and third is D and total length is 3 character.
3) 'M%' - List all product whose first character is M and having n length.
4) '%A%' - List all product having character is A at any place and having n length.
5) '_P%' - List all product whose second character is P and having n length.
6) '[I-S]%' - List all product whose first character between I and S and having n length.
See above example one by one.
1) 'L_ _' - List all product whose first character is L and total length is 3.
Example
Output
2) 'L_D' - List all product whose first character is L and third is D and total length is 3 character.
Example
Output
3) 'M%' - List all product whose first character is M and having n length.
Example
Output
4) '%A%' - List all product having character is A at any place and having n length.
Example
Output
5) '_P%' - List all product whose second character is P and having n length.
Example
Output
6) '[I-S]%' - List all product whose first character between I and S and having n length.
Example
Output