Clean up State field with T-SQL?

Posted by Pselus on Stack Overflow See other posts from Stack Overflow or by Pselus
Published on 2011-02-28T15:24:17Z Indexed on 2011/02/28 15:24 UTC
Read the original article Hit count: 239

Filed under:
|
|

The State field in our database is a mess. There was no validation when it was filled so we have everything from two letter abbreviations to full state names to misspelled state names to "test" and "xxxx", etc. I am not going to try to handle everything, but for sure I want to fix the correct state names to abbreviations. I have a list of valid state names and abbreviations, but I don't know how I can do this:

UPDATE Table SET State = ('AR','AK') WHERE (SELECT * FROM Table WHERE State IN ('Arkansas','Alaska'))

Basically, can I update a field to be something from a list by the location it is in another list?

© Stack Overflow or respective owner

Related posts about sql

Related posts about arrays