Ver Mensaje Individual
  #9 (permalink)  
Antiguo 26/02/2013, 08:41
leo_acn
 
Fecha de Ingreso: diciembre-2012
Mensajes: 83
Antigüedad: 11 años, 5 meses
Puntos: 4
Respuesta: comparación entre 2 tablas

select origen, emp, des_tipdocum, ano_vencimiento, TRAMO_AÑO,
CONVERT (NUMERIC(10,6),ISNULL(SUM(importe)/1000000,0))as Importe,
CONVERT (NUMERIC(10,6),ISNULL(SUM(importe2)/1000000,0))as Importe_2,
RUT_USO_MOVIL, Adquira, Proveedores, marca_minsal, Convert(NUMERIC(4),aaaa) as Año, Convert(nvarchar(20),
case when mm='01' then 'Enero'
when mm='02' then 'Febrero'
when mm='03' then 'Marzo'
when mm='04' then 'Abril'
when mm='05' then 'Mayo'
when mm='06' then 'Junio'
when mm='07' then 'Julio'
when mm='08' then 'Agosto'
when mm='09' then 'Septiembre'
when mm='10' then 'Octubre'
when mm='11' then 'Noviembre'
when mm='12' then 'Diciembre'
end) as 'Mes' into #apoyo
FROM TA_MORA
where [des_tipdocum]<>'DEVOLUCION' and
[des_tipdocum]<>'DOC. AUTORIZACION PAGO ADELANTADO' and
[des_tipdocum]<>'LÍQUIDO PRODUCTO'and
[des_tipdocum]<>'NOTA DE DEBITO'and
[origen]<>'Refovo' and
[TRAMO_AÑO]<>'2008 y más' and
[TRAMO_AÑO]<>'Vigente' and
[marca_minsal]<>'SI'
group by RUT_USO_MOVIL,mm,aaaa,origen,emp,des_tipdocum,ano_ vencimiento, TRAMO_AÑO, Adquira, Proveedores,marca_minsal
having RUT_USO_MOVIL<>''


delete from tabla where mes in(select distinct mes from #apoyo)
and año in(select distinct año from #apoyo)

insert into tabla
select * from #apoyo

drop tabla #apoyo


Lo que se me ocurrió es eso primero guardar los datos que vas a respaldar en una tabla temporal,
luego tomando el mes y el año de esa tabla temporal (#apoyo) puedes eliminarlos de tu tabla
finalmente solo guardas todo lo de la tabla teporal en la tabla de respaldo y borras la temporal, aunque como es temporal no es necesario xD
Bueno eso se me vino a la mente, tal vez los demas tengan una mejor solución, por mientras puedes intentar algo asi o se te ocurra una mejor
idea con ese ejemplo ;)

Saludos