SQLTeam.com | Weblogs | Forums

Like in where

I need a operator in "where" like:
example:

[] Represents any single character within the brackets
h[oa]t finds :
hot
hat
ht

I need find ht too

You will have to add that a separate condition in the WHERE clause, with OR:

WHERE column LIKE 'h[ao]t' OR column = 'ht'

so are you looking for exclusively for a and o?

thanks
but main example is more Complicated:

this is a better sampel
string: ab[c]de[f]ghij[k]lm

I want finds:
abcdefghijklm
abdefghijklm
abdeghijlm
abcdeghijklm
abcdefghijlm
....
roule:
into bracket set as optional:
(can point a character or can be empty)

into brackets set a optional (maybe a character maybe null )

declare @hot table(temp nvarchar(50))

insert into @hot(temp) values('hot'),('hat'),
('ht'),('H3t'),('git'),('hit'),('het')


select * 
 from @hot
 where temp LIKE 'h%t'

That value does not match the pattern because there's no "j" present.

As I stated before, there's no way to specify [k] AND to make that value optional, that is, "must be k or be no char at all".

Thanks

but

h%t

is not good because finds:
htttttto
hmmmmmo
hrrrrrrro

I don't want find this above

only:
a
OR
o
OR
empty

finds:
hot
hat
ht <-(this is important and difficult)

not really difficult, @ScottPletcher already answered it for you