merge into FORWARD_Position t1
using (select * from FORWARD_Position where PositionDate = 20110314 and type = 11) t2
on (t1.positiondate = t2.positiondate and t1.type = t2.type)
when matched then
     update set BuyAccount = 2, SellAccount = 3 WHERE t1.type = 11 and PositionDate = 20110314
when not matched then 
     insert (type, BuyAccount, SellAccount, PositionDate) values (11, 1, 2, 20110314)在where处报missing keyword的错误是什么原因

解决方案 »

  1.   

    -- where 条件不需要啦!因为已经有on (t1.positiondate = t2.positiondate and t1.type = t2.type)啦!
    merge into FORWARD_Position t1
    using (select * from FORWARD_Position where PositionDate = 20110314 and type = 11) t2
    on (t1.positiondate = t2.positiondate and t1.type = t2.type)
    when matched then
      update set t1.BuyAccount=2, t1.SellAccount=3
    when not matched then 
      insert (type, BuyAccount, SellAccount, PositionDate) 
      values (11, 1, 2, 20110314);