sql server 2012 - How to update multiple rows with same id in sql -


here code: getting error while updating rows

declare @xmldocument xml set @xmldocument =  '<employeezonemapping>   <employeezonedata>    <employeeid>5</employeeid>    <servicecirclezoneid>3</servicecirclezoneid>    <employeezonemappingstatus>1</employeezonemappingstatus>   </employeezonedata>  <employeezonedata> <employeeid>5</employeeid> <servicecirclezoneid>6</servicecirclezoneid> <employeezonemappingstatus>0</employeezonemappingstatus>   </employeezonedata> </employeezonemapping>'     ;with xmldata  ( select     a.details_employeezonemapping.value('(employeeid) [1]','int') employeeid,   a.details_employeezonemapping.value('(servicecirclezoneid) [1]','tinyint') servicecirclezoneid,   a.details_employeezonemapping.value('(employeezonemappingstatus) [1]','bit') employeezonemappingstatus  @xmldocument.nodes ('employeezonemapping/employeezonedata')  (details_employeezonemapping)) merge dbo.details_employeezonemapping t  using xmldata x on t.employeeid = x.employeeid  when matched           update set      t.servicecirclezoneid = x.servicecirclezoneid,    t.employeezonemappingstatus = x.employeezonemappingstatus   when not matched        insert(employeeid,servicecirclezoneid,employeezonemappingstatus)   values(x.employeeid, x.servicecirclezoneid, x.employeezonemappingstatus) ; 

error:

the merge statement attempted update or delete same row more once. happens when target row matches more 1 source row. merge statement cannot update/delete same row of target table multiple times. refine on clause ensure target row matches @ 1 source row, or use group clause group source rows.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -