====== pears.DistanceBetweenPostCodes ====== Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace. ===== Original SQL ===== create function "pears"."DistanceBetweenPostCodes"( /* Application Maintained Function / Procedure - DO NOT EDIT*/ in @PostCodeA char(20),in @PostCodeB char(20),in @Unit char(2) ) returns numeric(11,3) begin declare @EastingA numeric(11,3); declare @EastingB numeric(11,3); declare @NorthingA numeric(11,3); declare @NorthingB numeric(11,3); declare @Distance numeric(11,3); select first "Easting","Northing" into @EastingA,@NorthingA from "PostCodeLocation" where "PostCode" = "trim"(@PostCodeA); select first "Easting","Northing" into @EastingB,@NorthingB from "PostCodeLocation" where "PostCode" = "trim"(@PostCodeB); set @Distance = "sqrt"("power"("abs"(@NorthingA-@NorthingB),2)+"power"("abs"(@EastingA-@EastingB),2))/1000*if @Unit = 'Mi' then .621371192 else 1 endif; set @Distance = @Distance*cast("WPKMaintainGetSwitchValue"('POSTCODEMULT','GLOBAL','L') as double); return(@Distance) end