Código:
M_PERSONAL ---> esta tabla contiene mas de 282978 registrosselect 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_PAGOS ---> esta tabla contiene mas de 18257342 registros