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:
| ProductID | ProductName | Color | Price |
|---|---|---|---|
| 1 | Bicycle | Red | 1000 |
| 2 | Motorbike | Blue | 10000 |
| 3 | Car | Green | 20000 |
| 4 | Computer | Black | 20000 |
| Wildcard | Example | Answer | Description |
|---|---|---|---|
| Underscore (_) | SELECT ProductID FROM Product Where ProductName like ‘c_r’ | 3 | Denotes 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]%’ | 4 | Denotes any character not in brackets |