Trim Postcode (1 Viewer)

abbaddon223

Registered User.
Local time
Yesterday, 20:56
Joined
Mar 13, 2010
Messages
162
Hi all,

If anyone can help I'd be very grateful!

I'm trying to trim a postcode (easy) so that only the first two letters are left (finding not easy).

The issue I have is:

AB21 4LF
S21 2RE

IE I'm after

AB
S

If I trim from left or right based on the a space and characters to remove, the postcodes with only 3 IN characters end up wiped out...

Thanks in advance...
 

namliam

The Mailman - AWF VIP
Local time
Today, 05:56
Joined
Aug 11, 2003
Messages
11,695
left("S212RE", 2 + ( asc(mid(Ucase("S212RE"), 2,1)) < 64 ) )
S
left("AB214LF", 2 + ( asc(mid(Ucase("AB21 4LF"), 2,1)) < 64) )
AB

should work...
 

abbaddon223

Registered User.
Local time
Yesterday, 20:56
Joined
Mar 13, 2010
Messages
162
Hi,

Thanks for your response.

Would this work en-masse though? (IE I have 32K lines of data with all different postodes).

Thanks again.
 

G81

Registered User.
Local time
Today, 04:56
Joined
Jun 10, 2010
Messages
73
here's another way

i think postcodes have to start with a letter and are either one or two letters for the postcode area.

IIf(IsNumeric(Mid([postcode],2,1)),Left([postcode],1),Left([postcode],2))
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 04:56
Joined
Sep 12, 2006
Messages
15,692
assuming your postcodes are guaranteed well formatted then you could use something like this idea - which needs a bit of further attention

Code:
if isnumeric(char2) then
   leftpart = left(postcode,1)
else
   leftpart = left(postcode,2)
end if

on reflection i see this is the same idea as G81 above
 
Last edited:

namliam

The Mailman - AWF VIP
Local time
Today, 05:56
Joined
Aug 11, 2003
Messages
11,695
Hi,

Thanks for your response.

Would this work en-masse though? (IE I have 32K lines of data with all different postodes).

Thanks again.

YEs it should take for any and all postcodes the first (two) letters
 

Users who are viewing this thread

Top Bottom