Take the 2-minute tour ×

I'm importing data to a database. About 5000 rows each time. When im inserting into the DB one of the columns has a location. There are about 80 possible locations in total. I want to check each one of those and change it to a list of another 80 location names instead before I insert each row into the database. I have a switch statement helping me at the moment, but I was wondering if anyone thinks that this is a bad way to do it or whether I'm on the right track.

So basically at the moment. When I upload my data, that switch statement needs to be checked and a value changed 5000 times. Is switch the right way to go?

share|improve this question
I'm unsure of what you want? any code you already have or more details? –  Alex May 31 '12 at 9:07
add comment

3 Answers

up vote 5 down vote accepted

Don't use a switch statement, very hard to maintain. Create another table in your DB that maps your input location to the required database location and query off that instead. Makes it much easier to update/insert new locations etc, and keeps the length of your script to a sane level.

share|improve this answer
Thanks a lot for that –  kev670 May 31 '12 at 9:44
add comment

seems inappropriate to convert during the import process.

I would import the data as is, then either UPDATE the table, or use a lookup table as previously suggested

share|improve this answer
add comment

You could use a either a conversion table in your database or a Dictionary in your application instead of a switch.

share|improve this answer
add comment

Your Answer


