If I have a Postcode EH1 2GB
I am looking for a function which will pull only the EH
Ideally this would work for postcodes which may only contain 1 leading letter such as G2 1AB
and 2 numbers after the leading letters such as EH54 1BD and G25 2RD
I have tried using
I have tried pulling pulling the whole postcode and then using javascript (const extractPostalArea = (postalCode) => postalCode.match(/^[A-Z]+/)?.[0] ?? null;
) to further separate the Postcode, however this is causing more issues than it is solving.
Is there a way to pull the postcode that would give a result similar to the below table...
Postcode | PostalArea |
---|---|
B2 1GH | B |
EH2 4ED | EH |
SL4 5FR | SL |
E2W 4ST | E |
Any help would be much appreciated
I am using MariaDB
SELECT Company, Address, Town, Postcode From CollectionAddress
which has been working fine. When I addREGEXP_SUBSTR(Postcode,'[A-Z]+') AS PostalArea
to makeSELECT Company, Address, Town, Postcode, REGEXP_SUBSTR(Postcode,'[A-Z]+') AS PostalArea From CollectionAddress
it tells me that my query is syntactically wrong