如何用来自另一个表的5个不同的列更新同一列?

时间:2019-06-26 20:48:35

标签: tsql

我有5个不同的列    DISPNS_FEE_AMT,    PHRM_DISPNS_FEE_AMT,    PHRM_INGRDNT_COST_AMT,    PHRM_SALES_TAX_AMT,    RETL_SPRD_AMT,

and all of those Map to same column CLM_LN_AMT.
HOW CAN I UPDATE CLM_LN_AMT with the values from 5 different 
columns

Little background: CLM_LN_AMT(Table which also has column called CLM_LN_AMT) is populating Incorrect data to Dashboards. So we brought data from Hadoop which has correct data and needs to be updated in the CLM_LN_AMT column in CLM_LN_ANT table 

It needs to satisfy the following condition:
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.DISPNS_FEE_AMT
                 else a.CLM_LN_AMT
                 WHEN a.CLM_LN_AMT_TY_CD = 'CLTDSPFEE'
                      THEN a.CLM_LN_AMT   
                      ELSE 0                              
                  end

所有列

Update a
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.DISPNS_FEE_AMT
                 else a.CLM_LN_AMT
                 WHEN a.CLM_LN_AMT_TY_CD = 'CLTDSPFEE'
                 THEN a.CLM_LN_AMT   
                 ELSE 0                             
                 end,
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.PHRM_DISPNS_FEE_AMT
                 else a.CLM_LN_AMT
                 WHEN a.CLM_LN_AMT_TY_CD = 'PHDSPFEE'
                 THEN a.CLM_LN_AMT   
                 ELSE 0  
                  end,
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.PHRM_INGRDNT_COST_AMT
                 else a.CLM_LN_AMT
                 WHEN  a.CLM_LN_AMT_TY_CD = 'PHINGCOST'
                 THEN  a.CLM_LN_AMT     
                 ELSE 0  
                 end,
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.PHRM_SALES_TAX_AMT
                 else a.CLM_LN_AMT
                 WHEN a.CLM_LN_AMT_TY_CD = 'PHTSTAX '
                 THEN a.CLM_LN_AMT
                 ELSE 0  
Set CLM_LN_AMT = case when a.bus_seg_id in ('0519')
                 then b.RETL_SPRD_AMT
                 else a.CLM_LN_AMT
                 WHEN  a.CLM_LN_AMT_TY_CD = 'RETSPRD'
                 THEN  a.CLM_LN_AMT  
                 end


From CLM_LN_AMT a
Join RX_GAPS_GHTR_CORRECT_COLS b
On a.clm_sys_clm_id = b.clm_sys_clm_id
And a.bus_seg_id = b.bus_seg_id
And a.curr_rcd_ind = 'Y'
And a.updt_dt > <the last time we ran>

我希望将CLM_LN_AMT的值替换为RX_GAPS_GHTR_CORRECT_COLS。我加入后

0 个答案:

没有答案