Anu Furlan
Anu Furlan

Reputation: 13

Convert string to integer inside a where condition [MYSQL]

I would like convert a string parameter in a integer inside a where condition.

Case:

SELECT * FROM `pro` WHERE `fld_custom_1` <= '85';

I would like convert the '85'(STRING) in 85(INTEGER).

It's possible?

Upvotes: 1

Views: 7819

Answers (1)

juergen d
juergen d

Reputation: 204756

SELECT * FROM pro WHERE fld_custom_1 <= cast(@param as unsigned)

When fld_custom_1 is of a number data type then MySQL will automatically convert the string parameter to a number to make the comparision.

Upvotes: 1

Related Questions