Friday, 1 June 2012

LIKE statment in SQL

All except blanks:
Like '%'

Starting with A:
Like 'A%'
Or could do this: Like 'a%'

A somewhere in the field:
Like '%A%'
Or could do this: Like '%a%'

One character an A or B or D:
Like '[A,B,D]'
Or could do this: Like '[a,b,d]'

One character A through C as the first character:
Like '[A-C]%'
Or could do this: Like '[a-c]%'

A through C as the 1st character and A through H as the 2nd character:
Like '[A-C][A-H]%'
Or could do this: Like '[a-c][a-h]%'

Starting with Sm, ending with th, and anything for the 3rd character:
Like 'SM?TH'
Or could do this: Like 'sm?th'

Digit for the 1st character:
Like '#%'
Or could do this: Like '[0-9]%'

Not in a range of letters:
Like '[!a-c]'

Not start with a range of letters:
Like '[!a-c]%'

Not start with a number:
Or could do this: Like '[!0-9]%'

No comments:

Post a Comment