parent nodes: SQLapuntes | TrimestresSQL
Si tenemos el MES como nĂºmero
Lo pasamos a float,
lo dividimos entre 3
redondeamos hacia arriba
select I.MONTH, CEILING(CAST(I.month as FLOAT)/3) AS TRIMESTRE
from ancnotaryratesettletable I
where NOTARYID = '0103199' AND YEAR = 2015
| MONTH | TRIMESTRE |
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 2 |
| 5 | 2 |
| 6 | 2 |
| 7 | 3 |
| 8 | 3 |
| 9 | 3 |
| 10 | 4 |
| 11 | 4 |
| 12 | 4 |
Si tenemos FECHA en vez de mes
Sacar el mes de la fecha con DATEPART(MONTH, Columna_Fecha)
SELECT I.DATEENDMTH, DATEPART(MONTH, I.DATEENDMTH) AS MES
from ancnotaryratesettletable I
WHERE NOTARYID = '0103199' AND YEAR = 2015
| DATEENDMTH | MES |
| 2015-01-31 00:00:00.000 | 1 |
| 2015-02-28 00:00:00.000 | 2 |
| 2015-03-31 00:00:00.000 | 3 |
| 2015-04-30 00:00:00.000 | 4 |
| 2015-05-31 00:00:00.000 | 5 |
| 2015-06-30 00:00:00.000 | 6 |
| 2015-07-31 00:00:00.000 | 7 |
| 2015-08-31 00:00:00.000 | 8 |
| 2015-09-30 00:00:00.000 | 9 |
| 2015-10-31 00:00:00.000 | 10 |
| 2015-11-30 00:00:00.000 | 11 |
| 2015-12-31 00:00:00.000 | 12 |