tags:

views:

25

answers:

3

Hi,

In a sql based query, I need to check that the persons I select from data should have a cell phone with area code 256. How do we check this? I have cell phone numbers as BIGINT.

A: 

I assume you mean MySql 5.1.

In any case,

Select * from persons where persons.cellphonenumber % 10000000 == 256

Or something similar with the modulus operator.

J.Courtney
is there any other method?
shilps
How do we use Like function in this case?
shilps
It seems in any case such a solution would be messy since you're storing everything in a single column. In the ideal case, you could store the area code in a separate column. Given that, it seems that % is the best way to get at the 3 front digits while not converting to another data type (which would be equally messy).
J.Courtney
A: 

something like this:

select if(substr( convert(<your cell phone field>, char(20)), 1,3) = '256', 1, 0)


select if(substr( convert(25746744073709551615, char(20)), 1,3) = '256', 1, 0)

or you could use like:

select if(convert(25646744073709551615, char(20)) like '256%', 1, 0)
f00
A: 

have you tried simple soln like

mysql:
select * from table where cellno like '256%'

KoolKabin
i Think it shud work,let me try
shilps