mrc
mrc

Reputation: 3153

SQL Like pattern

I apply a left statement into field that need to one specified value if the result of the left operation is any char like 0 to 9, or X or Y.

The statement is

select case when T like '50%' and left(value,1) like '[0-9 X-Y]%' then 'Approved'

Is this pattern correct?

Thank you

Upvotes: 0

Views: 77

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Do one of:

select (case when T like '50%' and left(value, 1) like '[0-9 X-Y]' then 'Approved' . . .

or:

select (case when T like '50%' and value like '[0-9 X-Y]%' then 'Approved' . . .

There is generally no reason to mix left() with like.

Your version is technically correct. But the pattern is general (can match strings of any length) and you are only comparing to the first character in the pattern. That makes the statement awkward.

Upvotes: 3

Related Questions