这个UPDATE FROM使用case语句有什么问题?

时间:2010-04-24 17:01:33

标签: sql sql-server sql-update

update p
set p.storePrice = 
    CASE 
       WHEN p.costPrice BETWEEN 0.00 AND 1.00 
       THEN p.costPrice * 1.0
    CASE 
       WHEN p.costPrice BETWEEN 0.00 AND 1.00 
       THEN p.costPrice * 1.0
    ELSE 
       p.msrpPrice
    END
FROM product p                      
WHERE p.type = 1

错误说:

Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'CASE'.

我似乎无法看到sql的任何问题?

2 个答案:

答案 0 :(得分:4)

有两个起始case。删除第二个,如:

case 
    when x=1 then ...
    when x=2 then ...
end

答案 1 :(得分:2)

尝试:

UPDATE p
    SET 
     p.storePrice = 
            CASE 
                WHEN 
                    p.costPrice BETWEEN 0.00 AND 1.00 
                    THEN p.costPrice * 1.0

                WHEN 
                    p.costPrice BETWEEN 0.00 AND 1.00 
                    THEN p.costPrice * 1.0                              

                ELSE 
                    p.msrpPrice
            END
FROM product p                    
WHERE p.type = 1