SQL how to avoid duplicate insert in a table

Posted by user1624531 on Stack Overflow See other posts from Stack Overflow or by user1624531
Published on 2012-11-03T10:46:53Z Indexed on 2012/11/03 11:00 UTC
Read the original article Hit count: 197

Filed under:

how to avoid duplicate insert in a table? I use below query to insert in to table:

insert into RefundDetails(ID,StatusModified,RefundAmount,OrderNumber) 
  select O.id,O.StatusModified,OI.RefundAmount,O.OrderNumber 
  from Monsoon.dbo.[Order] as O  
  WITH (NOLOCK) JOIN Monsoon.dbo.OrderItem as OI  
  WITH (NOLOCK)on O.Id = OI.OrderId 
  WHERE o.ID in (SELECT OrderID 
                 FROM Mon2QB.dbo.monQB_OrderActivityView 
                 WHERE ACTIVITYTYPE = 4 AND at BETWEEN '10/30/2012' AND '11/3/2012') AND (O.StatusModified < '11/3/2012') 

© Stack Overflow or respective owner

Related posts about sql