ALTER PROCEDURE [dbo].[sp_remResumenPagoSES]
( 
@PERIODO INT = 0 ,
@MES INT = 0,
@ficini INT = 0,
@ficfin INT = 0,
@unineg INT = 0,
@DEP INT = 0,
@SEC INT = 0
)
AS
BEGIN
	SELECT COUNT(rut) AS TrabajadoresSES,
	SUM(dbo.remValorResultado(periodo,mes,ficha, 36)) AS RemuneracionTotal,
	SUM(dbo.remValorResultado(periodo,mes,ficha, 49)) AS TotalESV,
	SUM(dbo.remValorResultado(periodo,mes,ficha, 95)) AS TotalREP,
	SUM(dbo.remValorResultado(periodo,mes,ficha, 38)) AS TotalSIS
	FROM remTrabajadores
	WHERE
	periodo = @periodo
	AND mes = @MES
	AND	(ficha BETWEEN @ficini AND @ficfin)
	AND (@unineg = 0 or unidadNegocios = @unineg) 
	AND	(@DEP = 0 or departamento = @DEP) 
	AND (@SEC = 0 or seccion = @SEC)
	AND activo = 1
END