SQL

SQL Server Wild cards

A wildcard is used to represent one or more characters

The following Product table is used to explain the concept:

ProductIDProductNameColorPrice
1BicycleRed1000
2MotorbikeBlue10000
3CarGreen20000
4ComputerBlack20000
WildcardExampleAnswerDescription
Underscore (_)SELECT ProductID FROM Product Where ProductName like ‘c_r’3Denotes one character
Percent (%)SELECT ProductID FROM Product Where ProductName like ‘c%’3
4
Denotes one or more characters
Hyphen(-)SELECT ProductID FROM Product Where ProductName like ‘c[a-z]%’3
4
Denotes a character within the range
Square bracket []SELECT ProductID FROM Product Where ProductName like ‘c[ao]%’3
4
Denotes any character in brackets
Caret(^)SELECT ProductID FROM Product Where ProductName like ‘c[^a]%’4Denotes any character not in brackets