在更新语句中使用分组依据时出错

时间:2019-02-19 12:32:58

标签: sql sql-server sql-update

尝试将group by用于更新语句时出现错误

Update LegMove
set   Event_Code =  max(case when m.Status_Description = 'DPKL' then l.Status_Description else NULL end),                                                  
      Create_Date = max(case when m.Status_Description = 'DPKL' then dateadd(dd,datediff(dd,0,l.Move_Create_Timestamp),0) else NULL end), 
      PTimeStamp=max(case when m.Status_Description = 'DPKL' then l.Move_Create_Timestamp else NULL end), 
      Acrual_Date=max(case when m.Status_Description = 'DPKL' then dateadd(dd,datediff(dd,0,l.Move_Status_Timestamp),0) else NULL end), 
      Actual_TimeStamp=max(case when m.Status_Description = 'DPKL' then l.Move_Status_Timestamp else NULL end) , 
      Reason_Code=max(case when m.Status_Description = 'DPKL' then l.Move_Reason_Code else NULL end) , 
      Create_User=max(case when m.Status_Description = 'DPKL' then l.Move_Created_User else NULL end) from wrkLegMove m inner join MovementMaster l with(nolock) on l.Leg_Key = m.Leg_Key and l.Status_Description = m.Status_Description and l.Move_Create_Timestamp = m. FirstMoveTimewhere m.Status_Description in ('DPKL') 
group by m.Leg_Key, l.Shipment_Number, l.Shipment_Leg_Sequence

0 个答案:

没有答案