Maik Maik - 4 months ago 62
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


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.