Dashboard > Documentation for Metrix Users and Administrators > ... > Tips for Metrix Users > Create a Query based on a Zip Code range
Documentation for Metrix Users and Administrators Log In   View a printable version of the current page.
Create a Query based on a Zip Code range
Added by Anthony Hernandez, last edited by Anthony Hernandez on Jan 28, 2011  (view change)
Labels: 

Create a Query based on a Zip Code range

This query can be used to search for contacts within a zip code range.

  1. Navigate to the Query Manager
  2. Create a new Query
  3. Select an "Advanced Query" as the type and give it a name
  4. Copy & paste the SQL text into the SQL view of the Query editor
    SELECT     t12.AddressBlockWithCountry, CAST(LEFT(t1.ZIPPostalCode, 5) AS int) AS ZIP, t2.ContactName, t1.ZIPPostalCode
    FROM         dbo.tblContacts t2 LEFT OUTER JOIN
                          dbo.tblContactLocations t1 ON t2.ContactID = t1.ContactID LEFT OUTER JOIN
                          dbo.vwUtilQueryCommonAddressFields t12 ON t1.ContactLocationID = t12.ContactLocationID
    WHERE     (NOT (t2.fDelete = 1)) AND (t1.fDelete = 0 OR
                          t1.fDelete IS NULL) AND (NOT (t2.fDoNotContact = 1)) AND (t1.PCL = 1 OR
                          t1.PCL IS NULL) AND (IsNumeric(LEFT(t1.ZIPPostalCode, 5)) = 1) AND (CAST(LEFT(t1.ZIPPostalCode, 5) AS int) BETWEEN 10001 AND 10010)
  5. Save the Query and it's ready for use
Change the ZIP code range
Make sure to edit the zip code range by changing the numbers used in the last line of code.

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.1.1 Build:#406 Dec 23, 2005) - Bug/feature request - Contact Administrators