2011-06-21 29 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

@大衛:我是一個心靈讀者;-) –