Changing State Abbreviations to Full Name

Posted on 2009-04-30
Medium Priority
Last Modified: 2012-05-06
We have some data that provides state abbreviations (i.e. AL, DC, NM, VA, etc.); however, we need to be able to transition those values to the full names of the states, or numbers (i.e. Alabama would be 1, Alaska 2, etc.). Is there any way to do this within a T-SQL query?
Question by:rdracer58
LVL 41

Accepted Solution

Kyle Abrahams earned 960 total points
ID: 24274487
the easiest way would be to create a new table in your database.

id, abbreviation, state_name

you can then right functions to convert 1 to any other.

eg input id output abbreviation or state

If doing right from a select you could also just join the table.
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 960 total points
ID: 24274532
Create a table of states with the following columns:


If using SQL Server 2005+, you can always resort the order by using row_number() statement ordered by name ascending.  If not, you will have to resort order values on insert of new state name.

Then you can use the table of states to join to your data where abbreviations equal and then display either number or name.
LVL 27

Assisted Solution

by:Chris Luttrell
Chris Luttrell earned 80 total points
ID: 24274993
If you are wanting a list of all the states and their abbreviations you can get it off the USPS web site at http://www.usps.com/ncsc/lookups/abbreviations.html#states

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question