Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIKE Operator syntax

Status
Not open for further replies.

aas1611

Programmer
Dec 14, 2001
184
DE
Hallo,

Under MS SQL there is this syntax:
LIKE '[0-9]%'

I've tried this but it gave me an empty result.
What is the equivalent of that in MySQL?

The reason is, I have a field that contains alphabets (words), empty, marks (?,',^, etc) and numbers. I only want to select the ones with numbers only, otherwise it has to be replaced with zero.

Any idea anyone?
 
To replace non-numeric values with zero, you could use:
[tt]
SELECT
IF(
fld RLIKE '^[0-9]+$',
fld,
0
)
numfld
FROM tbl
[/tt]

RLIKE indicates the use of a regular expression. The ^ indicates the start of the string; the [0-9]+ means one or more digits; the $ means the end of the string.

You could also use REGEXP instead of RLIKE, and use a CASE expression instead of the IF.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top