Convert string to MYSQL integer

Asked

Viewed 19,465 times

5

What command can I use to convert string to integer in mysql? for example:

I am making the following list of tables:

SELECT mov . * , prod.produto, prod.unidade, prod.icms, prod.ipi, prod.codigo
FROM movimentacao AS mov, produtos AS prod
WHERE mov.Codigo = prod.codigo 

The field prod.codigo is with the value 0259 and the countryside mov.Codigo is with 259 and at the time of comparison they are not equal, I was wondering if you have any command that converts the value of the prod.codigo for whole to stay 259

  • 3

    Interesting that I could not reproduce the problem here, because comparing string with numeric as you described, the result was True. What version of Mysql and DB engine are being used?

3 answers

6


3

Just force a numeric operation on the string:

SELECT mov.* , prod.produto, prod.unidade, prod.icms, prod.ipi, cast(prod.codigo as unsigned integer)
FROM movimentacao AS mov, produtos AS prod
WHERE mov.Codigo = 0 + prod.codigo

3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.