update w_InvestorPaymentScheduleDetail as a
set PaymentNumber = (
select count(*) from w_InvestorPaymentScheduleDetail
where Investor='Billy Bar-Test-100944'
and InvestorPaymentScheduleMasterID='IPSM-100009'
and AssociatedInvestment='IID-1000074 25000' and ID < a.ID) + 1
where a.Investor='Billy Bar-Test-100944'
and a.InvestorPaymentScheduleMasterID='IPSM-100009'
and a.AssociatedInvestment='IID-1000074 25000'
order by a.Last_Update_Date desc,a.id asc错误提示:You can't specify target table 'a' for update in FROM clause

解决方案 »

  1.   

    提示说 update 不能用表的别名
      

  2.   

    update w_InvestorPaymentScheduleDetail as a,
    (select count(*) as num from w_InvestorPaymentScheduleDetail 
    where Investor='Billy Bar-Test-100944' 
    and InvestorPaymentScheduleMasterID='IPSM-100009' 
    and AssociatedInvestment='IID-1000074 25000' and ID  < a.ID) bset PaymentNumber =b.num+ 1 where a.Investor='Billy Bar-Test-100944' 
    and a.InvestorPaymentScheduleMasterID='IPSM-100009' 
    and a.AssociatedInvestment='IID-1000074 25000' 
    order by a.Last_Update_Date desc,a.id asc