Delete duplicate rows using Common Table Expression
Here is another way to delete duplicate rows by means of acommon table expression(CTE). The CTE will lookup the business keys that have duplicate values. then the delete statement will join the table to the CTE by the business key field.
WITH a (CustomerId, OrderId, numrecs)
select CustomerId, OrderId, COUNT(*) as numrecs
groupby CustomerId, OrderId havingCOUNT(*) > 1
FROM dbo.ImportOrders AS b
INNERJOIN a on a.CustomerId= b.CustomerId AND a.OrderId = b.OrderId