Duplicates in Table 1 are indentifies as follows;
select quote_ref, count (*)
from table 1
group by quote_ref
having count(*) > 1
Now I want the eliminate the duplicates based on the 2 rules below .
Take the entry that has the Status= Complete
If none in complete status then take the one with max([created_date ])
Else Flag to look at ?
Suppose I need a CASE statement with a delete, but not sure how to construct ?
For SQL Server 2005+, you can do the following:
In this case, I’m assuming that the row that you don’t want to delete is the one with
status = 'COMPLETE'or the one with the maximumcreated_date. If is the other way around, you can simply change theWHEREcondition.