Tuesday, January 5, 2010

Square brackets and Caret with Like Clause in SQL Server

The Like clause in SQL Server uses the following wildcard characters:
Percent (%)
Underscore (_)
Square Brackets ([])
Caret (^)
Most of us know about % and _ but what about the remaining wildcard characters so let us see them in details.
Square Brackets [] are used to replace any one char within a set or range of characters.
Let's see this Example for a set of characters:




So the result set will return any product name start by a,b or c.
Now let's see an example for range of characters:




So the result set will return any product name start by a,b,c or d.

Caret (^) is working as square bracket but in reverse way so [^a-c] means include all characters except the a,b or c.
Let's see this example :



So the result set will return all producat name does not start by a,b,c or d.

1 comment:

Unknown said...

Littel things that we don't care about it can solve big problems thanks abu Ahmad