views:

21

answers:

1

I have the following in a field ABCD, EFG, HIJ and can confirm this by selecting it. I need to be able to search this string for ABCD so I used the following:

case
when CHARINDEX(g.letters ,'ABCD') <> 0
then (- 2)
else (- 1)
end

However its always returning -1

+1  A: 

Try

CHARINDEX('ABCD', g.letters)

The first parameter is the expression to find and the second parameter is the expression to be searched.

Martin Smith
That'll teach me to post before properly searching! It seems a lot of people have this problem, what gives?
m.edmondson
@eddy556 - I can never remember this either!
Martin Smith
I would say intuition would put it the other way around?
m.edmondson
Just checked and in VB6 it *is* the other way round. `InStr("the cat sat on the mat", "cat")`
Martin Smith