2013-10-20 73 views
0

下面的代碼產生一個錯誤替換表的記錄:SQL查詢與另一

select lastname, firstname, workphone, homephone 
from members if (workphone is null) then workphone = homephone; 

我想從一個名爲members表中選擇lastnamesfirstnames和你的電話號碼。如果一個成員'workphone is null我需要用homephone替換它。

我會很樂意澄清,如果需要。

+0

*** ***什麼數據庫? SQL只是查詢語言.... –

+0

我已經加載了歌詞數據庫 – cryptomath

+0

爲什麼不把它拉下來做客戶端映射? – James

回答

0
select lastname, firstname, 
case when (workphone is null) then homephone else workphone end as workphone 
, homephone 
from members; 
+0

謝謝帕夫洛夫先生。您的更新答案實際上是解決方案。 – cryptomath

0

可以使用COALESCE函數,它返回它給了第一個不爲空的說法:

SELECT lastname, firstname, homephone, COALESCE(workphone, homephone) AS workphone 
FROM members