24

I want to achieve this:

SELECT * FROM linkledger WHERE toInt(reputation) > 100;

but the function toInt doesnt exist? Is there one?

I found this now but not working, which implies i have a more fundemental problem. BECAUSE THIS IS CORRECT

SELECT * FROM linkledger WHERE cast(reputation AS INTEGER) > 100;

Banned_User
  • 973
  • 2
  • 9
  • 17

2 Answers2

50

Use CAST(reputation AS INTEGER).

Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
2

I will leave Anik Islam Abhi's answer as the correct one because it will apply in most cases but I just want it on record that I only managed to fix the problem by just switching the variable to int

create table foo reputation int;

And then insuring Ints were inserted... I'm not sure what was happening that the correct answer didnt solve my problem.

Banned_User
  • 973
  • 2
  • 9
  • 17
  • What was its type previously? This is almost certainly the issue but you never told us. – Lightness Races in Orbit Oct 23 '14 at 12:01
  • Yeah I said it in the question title. It was a String. I tried having the engine cast for me, I tried to correct answer which i marked, and i even tried rounding the string. And also tried compairing the string number to a string number. – Banned_User Oct 24 '14 at 00:48
  • From [the documentation](http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast): _"To cast a string to a numeric value in numeric context, you normally do not have to do anything other than to use the string value as though it were a number"_. – Lightness Races in Orbit Oct 24 '14 at 03:37