Solved

mySQL compare string as numeric

Posted on 2010-11-15
2
416 Views
Last Modified: 2012-05-10
I'm querying a database I don't have control over. There is a string field which holds numbers, NULL and ''. What do I need to do to compare the string field as a number

Ex. I have the following values in the table
NULL
''
'0'
'1'
'2'
'11'

I want to select * from table where field < 2

It should only return 1 and 0 (I would also be OK with it treating NULL and '' as 0 and returning those), not the 11 or 2.
0
Comment
Question by:Darksbane
  • 2
2 Comments
 
LVL 6

Expert Comment

by:DalHorinek
ID: 34139122
Try select * from table where CAST(field, INT) < 2
0
 
LVL 6

Accepted Solution

by:
DalHorinek earned 500 total points
ID: 34139137
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now