使用WHERE,WHEN,THEN更新SQL中的多个字段

时间:2017-08-18 20:18:30

标签: sql

我需要在某些条件下更新多个字段。我知道我的语法不正确,但我无法弄清楚什么是错的,这应该很简单,但它不是点击。请帮忙。

UPDATE WO_TASK_LABOR
SET BILLING_RATE    
    WHEN SYSUR_AUTO_KEY = 577 THEN 26.51
    WHEN SYSUR_AUTO_KEY = 605 THEN 18.71
    WHEN SYSUR_AUTO_KEY = 637 THEN 16.84
    WHEN SYSUR_AUTO_KEY = 741 THEN 16.50
    WHEN SYSUR_AUTO_KEY = 792 THEN 26.00
    WHEN SYSUR_AUTO_KEY = 808 THEN 14.99
    WHEN SYSUR_AUTO_KEY = 812 THEN 24.51
    WHEN SYSUR_AUTO_KEY = 813 THEN 26.00
    WHEN SYSUR_AUTO_KEY = 884 THEN 28.00
    WHEN SYSUR_AUTO_KEY = 768 THEN 21.00
    WHEN SYSUR_AUTO_KEY = 892 THEN 21.50
    WHEN SYSUR_AUTO_KEY = 910 THEN 20.50
    WHEN SYSUR_AUTO_KEY = 920 THEN 22.00
    WHEN SYSUR_AUTO_KEY = 962 THEN 15.00
    WHEN SYSUR_AUTO_KEY = 970 THEN 23.00
    WHEN SYSUR_AUTO_KEY = 971 THEN 56.36
    WHEN SYSUR_AUTO_KEY = 977 THEN 16.00
    WHEN SYSUR_AUTO_KEY = 979 THEN 24.00
    WHEN SYSUR_AUTO_KEY = 982 THEN 20.00
    WHEN SYSUR_AUTO_KEY = 985 THEN 18.00
    WHEN SYSUR_AUTO_KEY = 828 THEN 26.50
    WHEN SYSUR_AUTO_KEY = 834 THEN 23.00    
END

1 个答案:

答案 0 :(得分:2)

您错过了CASE

UPDATE WO_TASK_LABOR
    SET BILLING_RATE = 
    CASE
    WHEN SYSUR_AUTO_KEY = 577 THEN 26.51
    WHEN SYSUR_AUTO_KEY = 605 THEN 18.71
    WHEN SYSUR_AUTO_KEY = 637 THEN 16.84
    WHEN SYSUR_AUTO_KEY = 741 THEN 16.50
    WHEN SYSUR_AUTO_KEY = 792 THEN 26.00
    WHEN SYSUR_AUTO_KEY = 808 THEN 14.99
    WHEN SYSUR_AUTO_KEY = 812 THEN 24.51
    WHEN SYSUR_AUTO_KEY = 813 THEN 26.00
    WHEN SYSUR_AUTO_KEY = 884 THEN 28.00
    WHEN SYSUR_AUTO_KEY = 768 THEN 21.00
    WHEN SYSUR_AUTO_KEY = 892 THEN 21.50
    WHEN SYSUR_AUTO_KEY = 910 THEN 20.50
    WHEN SYSUR_AUTO_KEY = 920 THEN 22.00
    WHEN SYSUR_AUTO_KEY = 962 THEN 15.00
    WHEN SYSUR_AUTO_KEY = 970 THEN 23.00
    WHEN SYSUR_AUTO_KEY = 971 THEN 56.36
    WHEN SYSUR_AUTO_KEY = 977 THEN 16.00
    WHEN SYSUR_AUTO_KEY = 979 THEN 24.00
    WHEN SYSUR_AUTO_KEY = 982 THEN 20.00
    WHEN SYSUR_AUTO_KEY = 985 THEN 18.00
    WHEN SYSUR_AUTO_KEY = 828 THEN 26.50
    WHEN SYSUR_AUTO_KEY = 834 THEN 23.00
    ELSE 0
    END
WHERE ENTRY_DATE >= '01-JUN-17'