= int(get_month(fn)) if ((mes == 1 or mes == 2 or mes == 11 or mes == 12 and 6 < hora <18) or
(mes == 3 and dia < 17 and 6 < hora < 18) or (mes == 3 and dia == 17 and 6 <= hora <18) or(mes == 3 a
WITH PivotData ASSELECT idWatimetro, mes,ano, valorSELECT *PIVOT(SUM(valor) FOR idWatimetro IN ([1],[2],[3],[4],[5] AS P order by mesWHERE (ano = 2012 and mes = 1 ) or (ano = 2012 and mes = 2)or
rdbms=sqlserver_2016&fiddle=f11f09035757a081ed540c85fc908bc8 SELECT '19/04/2021' as mes, '2021-03-20T00:00:00.000' as inicio_mes, '2021-03-31T23:59:59.000' as fin_mes UNION
SELECT '19/04/2021' as mes</em