0

以下代码会产生错误:

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

我正在尝试从名为 的表中选择lastnamesfirstnames您的电话号码members。如果成员的workphone is null我需要将其替换为homephone.

如果需要,我将非常乐意澄清。

4

2 回答 2

0

您可以使用该COALESCE函数,它返回给定的第一个非空参数:

SELECT lastname, firstname, homephone, COALESCE(workphone, homephone) AS workphone
FROM   members
于 2013-10-20T21:07:34.127 回答
0
select lastname, firstname, 
case when (workphone is null) then homephone  else workphone end as workphone 
, homephone 
from members;
于 2013-10-20T21:05:09.647 回答