I have a case where I have to pivot a temp table that I use in SP, this table must have a format by Number of Month example:
My sp executes the following :, but to achieve the above, a pivot is necessary, but I have sincerely tried to do it but I have not succeeded
SELECT IdFactura,SUM(total) as Total,datepart(day, datediff(day, 0, Fecha)/7 * 7)/7 + 1 as NumerWeek, Nombre from #Docs as pvt
GROUP BY IdFactura,Fecha,Nombre
PIVOT (SUM(pvt.total) FOR pvt.NumerWeek IN ([1],[2],[3],[4],[5],[6])) AS Child
ORDER BY IdFactura
DROP TABLE #Docs
END
I hope you can help me to make this case.