Maik Maik - 1 year ago 300
SQL Question

SQL Like pattern

I apply a

statement into field that need to one specified value if the result of the
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

Answer Source

Do one of:

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


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download