Subject SV: [firebird-support] Maths in the queries
Author Svein Erling Tysvær
Just a minor point of no real importance (I've no clue about your real question). Why not simplify this:

>WITH
> Z AS
> ( SELECT r.ID, r.OUTCODE, r.LAT AS LAT_D, r.LNG AS LNG_D,
> ( SELECT LNG_R FROM OUTCODEPOSTCODES
> WHERE OUTCODE = 'SA5') AS LNG_H,
> ( SELECT LAT_R FROM OUTCODEPOSTCODES
> WHERE OUTCODE = 'SA5') AS LAT_H
> FROM OUTCODEPOSTCODES r
> WHERE OUTCODE <> 'SA5'
> ),

to this

WITH
SA5(LNG_H, LAT_H) AS
( SELECT LNG_R, LAT_R FROM OUTCODEPOSTCODES
WHERE OUTCODE = 'SA5'),
Z AS
( SELECT r.ID, r.OUTCODE, r.LAT AS LAT_D, r.LNG AS LNG_D,
SA.LNG_H, SA.LAT_H
FROM OUTCODEPOSTCODES r
LEFT JOIN SA5 SA ON (1=1)
WHERE r.OUTCODE <> 'SA5'
),

Just an idea,
Set