Good morning gents,
I'm trying to write a query to identify the following
LIKE ('ABx%') where 'x' is another letter. Basically, I'm attempting to distinguish instances where the third character is a letter, not a number in an alpha string that begins with "AB" without resorting to
column LIKE ('AB%')
AND
( column NOT LIKE ('AB0%') OR
column NOT LIKE ('AB1%') OR
column NOT LIKE ('AB2%') OR
column NOT LIKE ('AB3%') OR
column NOT LIKE ('AB4%') OR
column NOT LIKE ('AB5%') OR
column NOT LIKE ('AB6%') OR
column NOT LIKE ('AB7%') OR
column NOT LIKE ('AB8%') OR
column NOT LIKE ('AB9%') )
Posts
If this is a large table and going to be used frequently, I probably wouldn't use that functionality. For a one time thing or something just done on occasion or a very small table, it's probably the quickest way of doing it.
[A-Za-z]
match uppercase and lowercase letters
so try
like ('AB[A-Za-z]%')
I think.
Or Not (Mid(Column,3,1)) between 0 and 9
Depends on the DB like mentioned above.
Doing like is slow, but it depends on the rest of the query (if the rest of the query throws away all but 40 rows, it's fine) and also on the indexing of the table. Some DB packages can optimize a regex on a column too.
Sounds like the OP doesn't need to worry about premature optimization right now.
?
In SyBase, which I think uses Transact-SQL, the only out-of-the-box method I can think of is this one: Basically, find the rows with an "AB" prefix, convert the third character to its ASCII code value and filter out any row where that value is between 48 and 57. Those are the ASCII codes for digits 0 through 9 respectively.