Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

State County City Problem Expand / Collapse
Author
Message
Posted Tuesday, July 9, 2013 7:58 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 1, 2015 11:54 AM
Points: 29, Visits: 66
Greetings. I would recommend you investigate how the US Census Bureau handles geography. In fact, they already have a comprehensive coding for State/County/Place for the entire US, including areas not covered by all levels of geography - like Native American land, islands, etc. A good place to start is their Guide to State and Local Geography:

http://www.census.gov/geo/reference/geoguide.html

You can find links to hierarchical diagrams, reference materials and other useful documents. You may find the article on ANSI codes of use:

http://www.census.gov/geo/reference/ansi.html

There is even a download page if you want to import there geographical codes:

http://geonames.usgs.gov/domestic/download_data.htm

Working with a major municipal government which happens to fall within five separate counties, we run into these issues a lot.

I would also caution you about using ZIP codes, as they are not really geographic areas but rather collections of postal carrier routes. In fact, the Census Bureau disclaims this on their page dealing with postal codes. US Postal Service builds their ZIP routes solely on business needs and cross city, county, even state lines with a single ZIP code.

The DBA mantra should always be "know your data, know your data" so understanding these relationships is important before you make business decisions based upon them. ZIP codes were meant to facilitate mail delivery - that is all. For other types of business, particularly Public Safety (which we support) you need something different.

I hope that this is useful to you.

Good luck.

Cheers.
Post #1471635
Posted Tuesday, July 9, 2013 8:02 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:13 PM
Points: 14,367, Visits: 14,111
Please note: this thread started in 2008.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1471637
Posted Wednesday, July 10, 2013 8:04 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, May 1, 2015 1:52 PM
Points: 2, Visits: 22

The census web site has raw data available for download. The data for each state will have one master "Geo" file for geography info with a primary key called LOGRECNO and related data files with a forign key of the same name. Look for a column called Summary level or Sumlev. The Summary level for Counties is identified as 050, places (cities) is 160 etc. The County and place columns wil give you the County or Place or identifer, sometimes referred to as the FIPS Code. The "Name" column wil give you it's name. You can query the geo file to get your information.

see the document below. Use the summary levels and other Geo identifying fields\columns will filter data accordingly. It is important to understand the table structures they use.
http://www.census.gov/acs/www/Downloads/handbooks/ACSGeneralHandbook.pdf

Maybe this will help.
Post #1472164
Posted Friday, June 26, 2015 5:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Yesterday @ 6:03 AM
Points: 1, Visits: 15
Great points in extending the data by everyone.

If we're working with just the tables in the question, you could replace the StateID column in the City table with a CountyID column so that the structure is:

State2 table:

StateID (Identity, primary key),
Name (full state name)
TwoLetterCode ('AL')

County2
CountyID (Identity, primary key),
Name (full county name),
StateID (from the State2 table)

City
CityID (Identity, primary key)
Name (full city name),
CountyID (from the County2 table, primary key)

Foreign keys:
County2.StateID to State2.StateID
County2.CountyID to City.CountyID
Post #1698039
Posted Friday, June 26, 2015 6:13 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:06 PM
Points: 42,481, Visits: 39,277
Please note: 7 year old thread.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1698049
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse