|    
			
				01/09/2008, 10:49
			
			
			  | 
  |   |  | Colaborador |  |  Fecha de Ingreso: julio-2007 Ubicación: Mexico, D.F. 
						Mensajes: 6.482
					 Antigüedad: 18 años, 3 meses Puntos: 180 |  | 
  |  Respuesta: registros repetidos  
  -- Creo mi tabla de paso con los registros duplicadosSELECT COUNT(*) - 1 as Rows, col1, col2
 INTO #DuplicateRecords
 FROM MyTabla
 GROUP BY COL1, COL2
 HAVING COUNT(*) > 1
 -- Inicio con mi rutina de ELIMINACION DE DUPLICADOS
 DECLARE @Record int
 DECLARE @RowsDel int
 -- Las variables a comparar, deben ser del mismo tipo de la tabla orgen
 DECLARE @COL1Del int,
 DECLARE @COL2Del varchar(10)
 WHILE EXISTS(SELECT * FROM #DuplicateRecords)
 BEGIN
 SELECT TOP 1 @RowsDel = Rows, @COL1Del = col1, @COL2Del = col2
 FROM #DuplicateRecords
 SET ROWCOUNT @RowsDel
 DELETE MyTabla WHERE col1 = @COL1Del AND col2 = @COL2Del
 DELETE #DuplicateRecords WHERE col1 = @COL1Del AND col2 = @COL2Del
 SET ROWCOUNT 0
 CONTINUE
 END
     |