Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/06/2011, 09:31
Erick21
 
Fecha de Ingreso: abril-2010
Ubicación: Lima-Peru
Mensajes: 96
Antigüedad: 14 años
Puntos: 2
Optimizar Consulta

Hola amigos Foros web , tengo esta consulta la cual funciona pero demora demasiado en darme el resultado necesito optimnizarla. gracias de antemano

Código:
select  Id_Per into #QU from M_PERSONAL where IdCp= 820

select  SUM(M_Sueldo) as Total,
		SUM((case when R.M_Sueldo = 0 then R.M_Sueldo+R.N_Bonif else 0 end)) as Deuda
		from M_PAGOS R inner join #QU A on A.Id_Per=R.Id_Per
	where  R.IdTram in ('02.01','11.00','11.04') and 
		   R.F_Año between '1997' and '2010'
   
 drop table #QU
M_PERSONAL ---> esta tabla contiene mas de 282978 registros
M_PAGOS ---> esta tabla contiene mas de 18257342 registros