2011-06-21 30 views
5

我下面的表格与属性SQL问题:如何避免200个If-Else语句?

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

表2声明重命名规则“old_profile”到“new_profile”(例如,如果old_profile被称为“Banana300”,该new_profile应该叫“Chocolate125”) 。

有谁知道是否有可能用SQL/MS Access Query执行该操作?

如果不是,我将不得不为此任务编写一个外部脚本。

非常感谢。

干杯

编辑:我忘了明确提到,我想从表1和表2表3创建(忽略“some_more_attributes”)。

+1

执行什么?你想达到什么目的? – StevieG

回答

5

如果我明白你的问题:

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

非常感谢,你救了我一些代码:) –

+0

你到底怎么知道这个问题? –

+2

@大卫:我是一个心灵读者;-) –