StateForZip()

<< Click to Display Table of Contents >>

Navigation:  Available Functions >

StateForZip()

Syntax

StateForZip( <CharacterValue>, <NumericValue> )

 

Purpose

Given a specific zip code, this function will return the name of the state associated with the zip code. Normally only one state is associated with a zip code, but if multiple states are associated with the zip code, a specific associated state code may be fetched by passing the number of the desired associated state as the second parameter. Passing zero for the second parameter will cause the StateForZip() to return the number of states associated with the given zip code. Very few zip codes in the United States cross state lines.

 

Parameters

<CharacterValue> may be the name of any character field, but is usually the Zip field. A character (alpha-numeric) field is used for zip codes since they may contain a dash.

 

<NumericValue> is an optional parameter which specifies which state to return for the given zip code (most zip codes have only one state associated with them). If omitted, the first associated state will be returned. If passed as zero, then a count of the number of states associated with the given zip code will be returned.

 

Returns

The name of the state associated with the given zip code. Or, if <NumericValue> is zero, the number of states associated with the given zip code.

 

Usage

This function can be used with custom selections. For example, a custom selection could be written to find all the constituents in a zip code crossing multiple states, or dedicated to a single state.  

 

Example

The following examples illustrate various results of StateForZip():

 

CALL

RESULT

StateForZip( .Zip., 0 ) > 1

True if zip borders crosses multiple states.

StateForZip( .Zip., 0 ) = 1

True if zip contained within a single state.

StateForZip( "83864" )

ID

StateForZip( "83864", 0 )

1

StateForZip( "83864", 1 )

ID