WILDCARD characters are used to substitute one or more characters in a string and used with LIKE operator which is used in a WHERE clause to search for a specified pattern in a column.
Syntax in SQL to use Wildcard characters –
SELECT(ColumnName(s)) FROM <TableName> WHERE<ColumnName>LIKE <pattern> ;
Examples of wildcard characters use in SQL-
Replace the word pattern provided in below example with the pattern provided in following table, its result is explained in table.
SELECT * FROM Customers WHERE CustomerName LIKE ‘pattern’;
Wildcard characters in SQL Server-
Symbol | Represents | Pattern | Query result returns customer name having character |
% | Zero or more characters | ab% | a at 1st and b at 2nd position |
_ | A single character | a_d | a at 1st and d at 3rd position |
[] | Any single character within [] | a[mo]d | a at 1St & d at 3rd & either m or o at 2nd position |
^ | Any single character not in [] | a[^mo]d | a at 1St & d at 3rd & neither m nor o at 2nd position |
– | Any single character within given range | a[m-p]d | a at 1St , d at 3rd & any 1 from range m-p at 2nd position |