SQL Question: How to avoid 200 If-Else Statementments?

I have the following tables with attributes

Table1: [username]    [old_profile]
Table2: [old_profile] [new_profile]
Table3: [username]    [new_profile]    [some_more_attributes]

Table 2 declares the rules for renaming "old_profile" to "new_profile" (for example, if old_profile was called by "Banana300", the new_file should be called by "Chocolate125").

Does anyone know if it is possible to accomplish this using an SQL / MS Access query?

If not, I would have to write an external script for this task.

Many thanks.

Greetings

EDIT: I forgot to indicate that I want to create table3 from table 1 and table2 (ignore "some_more_attributes").

+5
source share
1 answer

If I understood your question:

INSERT INTO table3 (username, newprofile) 
SELECT t1.username, t2.newprofile
FROM table1 t1 INNER JOIN table2 t2 ON t1.oldProfile = t2.OldProfile
+5

All Articles