• Sean Lange (10/10/2012)


    Not 100% sure what you are trying to do here. It sounds like you want to delete duplicates from a table? This seems like an awfully complicated way to go about it.

    The error you are getting is because you trying to compare entire result sets and what you want is the row count.

    IF (Select * From SoureTable) > (Select Distinct * From SourceTable)

    That doesn't work. That is trying to compare the table to itself which just doesn't make any sense. You should instead use:

    IF (Select count(*) From SoureTable) > (Select count(distinct *) From SourceTable)

    Even though this will fix the error it seems like you could just remove the duplicates a lot easier than copying millions of rows to another table and then copying them back. Seems a lot more efficient to just delete the duplicates.

    Thanks Sean,

    You are correct all i want to do is just delete the duplicate rows. Looks like I need to revisit this another way and look for better fixes using row counts or some other option.