473,503 Members | 8,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a range on Postcode in sql

1 New Member
Hiya, I am trying to select based on a range on postcode on a table. The field POSTCODE is a varchar2(8).

The problem is when refinng on 'where postcode between 'PE1' and 'PE29'', because this is a character field and not a number field, 'PE3','PE4','PE5','PE6','PE7','PE8','PE9' are all ignored because the construct orders in characters and then numbers and as a result the query excludes it.

Can anyone provide some code to overcome this taking into account all the variation of postcodes i.e WV14 5YT, WV4 6TR, B1 8JB etc... I managed to find the attached code but there is a variation of postcode that causes this to fail:

select decode(instr(upper(postcode),'B'),1 ,substr(postcode,1,1)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),2,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode)),
decode(instr(upper(postcode),'G'),1
,substr(postcode,1,1)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),2,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode)),
decode(instr(upper(postcode),'EC'),1
,substr(postcode,1,2)||substr(postcode,3,length(po stcode)-2),
decode(instr(upper(postcode),'NW'),1
,substr(postcode,1,2)||substr(postcode,3,length(po stcode)-2),
decode(instr(upper(postcode),'SW'),1
,substr(postcode,1,2)||substr(postcode,3,length(po stcode)-2),
decode(instr(upper(postcode),'SE'),1
,substr(postcode,1,2)||substr(postcode,3,length(po stcode)-2),
decode(instr(upper(postcode),'WC'),1
,substr(postcode,1,2)||substr(postcode,3,length(po stcode)-2),
decode(instr(upper(postcode),'L'),1
,substr(postcode,1,1)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),2,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode)),
decode(instr(upper(postcode),'M'),1
,substr(postcode,1,1)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),2,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode)),
decode(instr(upper(postcode),'S'),1
,substr(postcode,1,1)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),2,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode))
,substr(postcode,1,2)||lpad(to_number(substr(subst r(postcode,1,length(postcode)-3),3,2)),2,'0')||
substr(postcode,length(postcode)-3,length(postcode))))))))))))
from temp order by 1;
Aug 10 '07 #1
0 2008

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4101
by: Lapchien | last post by:
I have a field for a postcode. I'd like another field to auto contain an 'area' number, based on the first part (only) of the postcode. For example, if a postcode LS4 4DJ was entered, another...
0
1888
by: Fraser Dickson | last post by:
I am building a web based system using ASP.NET and VB.NET which has to interact with a web service which uses XML WDDX packets. I have been given the XML Packet Specification by the Web Service...
5
6212
by: Alan | last post by:
Hi, I'm getting as bit confused with my queries. I simply (!) want to insert a space into a postcode field the 4th character from the right, so, for example, ML201TQ becomes ML20 1TQ, which is...
1
1821
by: miz_luvly | last post by:
hi guyz I have searched google and had no luck. I am trying to create a form where user enter postcode and address box fills up automatically from the back-end db. can anyone guide me on how...
3
2367
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
8
4117
by: warezguy05 | last post by:
Hi I'd like to forward users to a 'thank-you' page after they've submitted a form. I used this code and it worked perfectly till yesterday; header("Location:...
12
1898
by: xhe | last post by:
I am now developing a website which needs Canadian PostCode Database. I can certainly buy one, but that will cost my hundered of $$, and my website is only for education purpose, it won't make...
0
1713
by: DMcN | last post by:
Hi, I have a form set up in flash pointing to a PHP script on my webspace. I checked the PHP script and when viewed in a browser it returns the parameters OK so I presume it is working. My...
1
2023
by: dominicowen | last post by:
Hi, I have a customer database in Access 2003 with customers postcodes. What I want to do is type in a postcode on access and it will link the postcode on to googlemaps without having to type...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.