
December 10th, 2012, 11:10 AM
|
 |
For POny!
|
|
Join Date: Apr 2012
Location: Amsterdam
|
|
|
Range of Doom Postal codes
Hi guys, I am the unfortunate man to have the task to extract from a database the email addresses that fall in a range of postal codes. The data is horrible and the only consequent thing which I want to sort on are the first 4 digits.
Example data
8763 BA
2451XA
1341-BC
For instance get all email addresses that fall in a range between 1200 and 1400. This is what I tried:
Code:
SELECT email, pcode FROM chaos_table_of_doom WHERE pcode BETWEEN
(SUBSTRING(pcode,1,4) = 1200)
AND
(SUBSTRING(pcode,1,4) = 1400)
LIMIT 0, 200;
This doesn't quite work (the pcodes don't match)
Anyone maybe knows a good way to do this (apart from firing the guy that created this table)
-EDIT: ok i think I fixed it but if someone has a better method let me know 
Working code used:
Code:
SELECT email, pcode FROM chaos_table_of_doom WHERE SUBSTRING(pcode,1,4) >= 1200
AND
SUBSTRING(pcode,1,4) =< 1400
LIMIT 0, 200;
Last edited by aeternus : December 10th, 2012 at 02:29 PM.
|