SQL Server中的语法错误不正确

时间:2016-02-18 19:36:08

标签: sql-server-2008

UPDATE SHIPPER_LINE
SET ACT_FREIGHT =
convert(decimal(10,2),
(CASE

WHEN CAST(RATE AS FLOAT) >= 0 AND CAST(RATE AS FLOAT) <= 105 THEN    
CAST(RATE AS FLOAT) * 1.2

WHEN CAST(RATE AS FLOAT) >= 105.01 AND CAST(RATE AS FLOAT) <= 145.99 THEN 
CAST(RATE AS FLOAT) = 146

WHEN CAST(RATE AS FLOAT) >= 146 THEN CAST(RATE AS FLOAT) * 1.06

ELSE CAST(Rate AS Float)

END))

以上是我正在编辑的现有触发器的一部分。我在'Cast(rate as float)= 146'部分的'='符号下面出现语法错误。在指定范围内使'Rate'等于146的正确语法是什么?

1 个答案:

答案 0 :(得分:0)

您是要更新RATE还是使用值146

你不能在这里做第一个,第二个只是返回146

UPDATE SHIPPER_LINE
SET ACT_FREIGHT = convert(DECIMAL(10, 2), (
            CASE 
                WHEN CAST(RATE AS FLOAT) >= 0
                 AND CAST(RATE AS FLOAT) <= 105
                    THEN CAST(RATE AS FLOAT) * 1.2
                WHEN CAST(RATE AS FLOAT) >= 105.01
                 AND CAST(RATE AS FLOAT) <= 145.99
                    THEN 146    -- just return the value
                WHEN CAST(RATE AS FLOAT) >= 146
                    THEN CAST(RATE AS FLOAT) * 1.06
                ELSE CAST(Rate AS FLOAT)
                END
            ))