I have one table main_cohort
that has two different columns which contain zip codes in 3 digit and 5 digit numeric form (e.g. 100 or 10017), zip_value3
and zip_value5
, and I want to join it with another table zip_codes
that has these same columns as well as an additional column, city_name
, that has the text string of the city associated with each zip.
I want to replace the numeric values on the first table with the names of the cities on the second table. So for instance, if I have a customer_id in 'main_cohort' that has a 'zip_value3' of 100, I want to replace that in my output with the value from the city_name
from the zip_code
table, which would be New York.
I am guessing that you want one city, first checking the 5-digit zip code and then the 3-digit one:
# Table - tbl_MainCohort #
CustomerID Zip_Value3 Zip_Value5
Table - tbl_ZipCodes
ZipID Zip_Value3 Zip_Value5 City_Name