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