1

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?

2
  • MySQL usually does such things automatically; heck, it will even usually convert '85absdaojfiwefmwef' to 85. Commented Aug 4, 2016 at 16:29
  • See also: dev.mysql.com/doc/refman/5.7/en/cast-functions.html CAST() and CONVERT() Commented Aug 4, 2016 at 16:30

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

5 Comments

Good point, in my comment I had assumed the OP was comparing to an int field; likely an incorrect assumption if they are having problems.
Yeah, it's a varchar(255) type. Unfortunately i can't remove the ' ' and i must work inside them.. Somethings like '(85)INT'
Like in my answer: cast('85' as unsigned)
Thanks for the answer but i must work inside the ' ' and i can't add nothing before or after them,
Ah, you mean you can't change the query? Then you are out of luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.