Database Reference
In-Depth Information
Like operator
The Like operator is a versatile SQL function that allows you to perform sophisticated string pattern
searching in your query. Here's a basic Like operator:
Select AccountType
From dbo.DimAccount
Where AccountType Like 'Balances'
This query returns only records where the AccountType value is exactly equal to Balances . So far
this does not seem like anything special; you can achieve the same results using an = (equal) operator.
However, the power of the Like operator stems from the use of wildcard characters. SQL Server
includes four wildcard characters.
See TableĀ 9-1 for how to use wildcards.
TableĀ 9-1: Examples of Wildcard Characters
Wildcard
Character(s)
What It Does
Used with Like
Result
Like 'Ba%'
Indicates any string
Returns all rows where
AccountType starts with Ba
Returns all rows where
AccountType includes the
letter a
%
Like '%a%'
Indicates any single
character
Returns all rows where
AccountType is composed of
8 letters that end with
alances
_
Like '_alances'
Like '[a-k]
alances'
Indicates any single char-
acter within a specified
range
Returns all rows where
AccountType starts with a
letter between a and k and
ends with alances
Returns all rows where
AccountType starts with the
letter a , b , or c and ends with
alances
[ ]
Like '[abc]
alances'
Indicates any single char-
acter not within a speci-
fied range
Like '[^c-k]
alances'
Returns all rows where
AccountType does not start a
letter between c and k and
ends with alances
Returns all rows where
AccountType does not start
with the letter c , d , or f and
ends with alances
[^]
Like '[^cdf]
alances'
 
Search WWH ::




Custom Search