About Me

My photo
MCTS FOR SQL SERVER 2008 DOT NET PROGRAMMING WEB DESIGNING

Friday, 10 February 2012

merge statement

syntax here:-

merge itemorders as d using (select itemid,sum(b.qtyissued)as issuedqty from sales a, salesdetails b where
a.orderno=b.orderno and a.orderid=11 and dbo.dateonly(a.orderdate)>'2011/12/1' group by itemid)c
on d.itemid=c.itemid
when matched and d.qty-c.orderqty<=0
then delete
when matched
then update set d.qty=d.qty-c.orderty
output $action,inserted.qty,inserted.itemid,deleted.qty,deleted.itemid;

No comments:

Post a Comment