CRM-14720 - smart groups based on postal code numeric ranges cause fatal
authorEileen <eileen@fuzion.co.nz>
Wed, 21 May 2014 09:07:52 +0000 (05:07 -0400)
committereileenmcnaughton <eileen@fuzion.co.nz>
Mon, 12 Oct 2015 07:18:07 +0000 (07:18 +0000)
CRM/Contact/BAO/Query.php

index 04778d5076759b612a2bbc7e3b8393a8511732c2..f21943efa8cfb9073915f7db4579d6d7897a26f4 100644 (file)
@@ -3515,7 +3515,7 @@ WHERE  $smartGroupClause
 
     // Handle numeric postal code range searches properly by casting the column as numeric
     if (is_numeric($value)) {
-      $field = 'ROUND(civicrm_address.postal_code)';
+      $field = "IF (civicrm_address.postal_code REGEXP '^[0-9]+$', CAST(civicrm_address.postal_code AS UNSIGNED), 0)";
       $val = CRM_Utils_Type::escape($value, 'Integer');
     }
     else {