HOW TO USE WILDCARD CHARACTERS IN SQL

Wildcard in SQL

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-

SymbolRepresentsPatternQuery result returns customer name having character
%Zero or more charactersab%a at 1st and b at 2nd position
_A single charactera_da at 1st  and d at 3rd  position
[]Any single character within []a[mo]da at 1St  & d at 3rd  & either m or o at 2nd position
^Any single character not in []a[^mo]da at 1St  & d at 3rd  & neither m nor o at 2nd position
Any single character within given rangea[m-p]da at 1St , d at 3rd  & any 1 from range m-p at 2nd position
Wildcard characters usage in SQL

Leave a Reply

Your email address will not be published. Required fields are marked *