使用案例计算的Update语句中的语法错误

时间:2019-01-31 02:21:46

标签: sql sql-server-2016 ssms-2016

我正在尝试根据订单是在多个细分市场中还是在单个细分市场中,根据驱动程序类型来计算驱动程序的百分比工资。我成功地测试了每个部分,但“发件人”带有红色下划线,执行该命令时出现语法错误。这是我正在尝试的脚本:

update legheader
set lgh_extrainfo1 =  ( 
Select Case  When L.lgh_split_flag <> 'N' and L.lgh_carrier = 'UNKNOWN'
       Then Case 
            When 
            TR.trc_type1 = 'O/O' and TR.trc_type3 = '70Per'
            Then CAST (.7 * ((Cast (L.lgh_miles as decimal (10,2))/O.ord_totalmiles) * L.lgh_ord_charge)as decimal (10,2))
            When 
            TR.trc_type1 = 'O/O' and TR.trc_type3 <> '70Per'
            Then CAST (.64 * ((Cast (L.lgh_miles as decimal (10,2))/O.ord_totalmiles) * L.lgh_ord_charge)as decimal (10,2))


            When L.lgh_split_flag = 'N' and L.lgh_carrier = 'UNKNOWN' 
            Then Case
            When  
            TR.trc_type1 = 'O/O' and TR.trc_type3 = '70Per'
            Then CAST (.7 * L.lgh_ord_charge as decimal (10,2))
            When 
            TR.trc_type1 = 'O/O' and TR.trc_type3 <> '70Per'
            Then CAST (.64 * L.lgh_ord_charge as decimal (10,2))


        End    

From Legheader L Left Join TractorProfile TR on L.lgh_tractor = TR.trc_number
                 Left Join Orderheader O on O.ord_hdrnumber = L.ord_hdrnumber)

1 个答案:

答案 0 :(得分:0)

您可以尝试以下查询。在这里,您会错过嵌套END的{​​{1}}语句。

CASE