我仅在工作电话以08开头时才尝试更新列

时间:2018-12-04 12:12:33

标签: sql sql-update where-clause

UPDATE Contact
  SET MobilePhone = WorkPhone
    WHERE left(WorkPhone, 2) LIKE '%01%' 
      and MobilePhone = NULL and User = 992;

2 个答案:

答案 0 :(得分:1)

您可以尝试以下操作-您需要添加MobilePhone is NULL而不是MobilePhone = NULL

UPDATE Contact
  SET MobilePhone = WorkPhone
    WHERE left(WorkPhone, 2) LIKE '08%' 
      and MobilePhone is NULL and User = 992;

答案 1 :(得分:1)

这是您想要的吗?

UPDATE Contact
    SET MobilePhone = WorkPhone
    WHERE WorkPhone LIKE '08%' AND  -- WorkPhone starts with "08"
          MobilePhone IS NULL AND    -- Probably your real problem
          User = 992;

仅将LIKE用于“开头为”。您的标题为“ 08”,因此使用了它。

您真正的问题可能是= NULL,因为它永远不会返回true,因此不会更新任何行。