Hello friends, I'm here to request your important contribution I have this Script
SELECT
ISNULL(mes,0)[mes],
ISNULL(Cod_Area,0)[Codigo Area],
ISNULL(nom_emp,0)[Nombre Empleado],
ISNULL(Cod_Puesto,0)[Codigo Puesto],
ISNULL(Puesto,0)[Puesto],
ISNULL ([LENTES],0)[LENTES],
Fecha_Gestion,
ISNULL ([AYUDA ODONTOLOGICA],0)[AYUDA ODONTOLOGICA],
Fecha_Gestion,
ISNULL ([DEFUNCION DE FAMILIA],0)[DEFUNCION DE FAMILIA],
Fecha_Gestion,
ISNULL ([AYUDA MATERNIDAD],0)[AYUDA MATERNIDAD],
Fecha_Gestion,
ISNULL ([AYUDA MEDICAMENTOS (R.L.)],0)[AYUDA MEDICAMENTOS (R.L.)],
Fecha_Gestion
FROM
(SELECT m.mes,tp.Cod_Area,tp.Cod_Puesto,Puesto, me.nom_emp,TB.Tipo_Benef,Monto,Fecha_Gestion
FROM Tabla_Principal AS tp
INNER JOIN Mes AS m ON M.id=TP.mes
INNER JOIN Tipo_Beneficio AS tb ON TB.Id=TP.Tipo_Benef
INNER JOIN Maestro_Empl AS me ON me.No_emp = tp.No_emp
UNION ALL
) AS TablaDatos
PIVOT
(
SUM (Monto)
FOR Tipo_Benef IN ([LENTES],[AYUDA ODONTOLOGICA],[DEFUNCION DE FAMILIA],[AYUDA MATERNIDAD],[AYUDA MEDICAMENTOS (R.L.)])
)AS PivotTable
;
Open a way that I can add the total of each one the amount per month example