What do you guys think would be the best approach here? I have about 30 SQL tables that is basically referenced by a [lookup] table. I have to do an insert in another table [FinalTable] for each row in the [lookup] table. Now the [lookup] table looks something like this.
ID, Zipcode, tableID
1, 60453, 1
2, 90210, 1
3, 60453, 2
4, 60625, 3
5, 60625, 4
6, 60625, 4
7, 60625, 5
there's a tableID that lets me know which of the 30 tables I need to get data from. and then using the zipcode i do a select on that table and insert whatever data set is returned
Using a Cursor to go through each row of the [lookup] table, what would be the best approach here? in terms of efficiency and the fastest queries. and how would one go about making the table selection dynamically in SQL statements? the [lookup] table has about 1k rows of data and would not grow much in the future. but this whole selecting and inserting process needs to be repeated on a monthly basis. let me know what you guys think. thanks.
All the approaches i have so far. Unfortunately, I have only SQL at my disposal. can't use anything else.
- putting everything in an if-else statement for selecting the different tables and inserts?
- using case switch statement?
- writing 30 stored procs for each table?
i would love to change the design but unfortunately, the 30 disjointed tables comes from a client's DB, basic csv flat files we just uploads. the same zipcodes would appear at multiple tables and we have to do inserts based on which table we are suppose to get data from. sucks. how can i fix this?