How to convert the month of the date to text?

2

I want my months that are numeric to be displayed in text, but I do not know the correct way to use the datename. Thanks

 SELECT SUM(AU.Tarifa_Diaria) AS [TOTAL],MONTH (AO.fTermino) AS [MES]
 FROM Arriendo_Autos AU INNER JOIN Arriendo_Solicitud AO
 ON AU.Patente = AO.Patente
 GROUP BY MONTH (AO.fTermino)
    
asked by Daniela 31.10.2018 в 13:20
source

2 answers

1

Indeed, you can use the datename , which would be used as follows

SELECT   SUM(AU.Tarifa_Diaria) AS [TOTAL]
       , datename (month, AO.fTermino) AS [MES]
  FROM Arriendo_Autos AU 
       INNER JOIN Arriendo_Solicitud AO ON AU.Patente = AO.Patente
 GROUP BY datename(month, AO.fTermino)

In the first parameter of datename , in addition to month you can use the values year , quarter , day , week , weekday , among others.

The result would look something like:

TOTAL                                   MES
--------------------------------------- ------------------------------
1.0                                     Enero

(1 row(s) affected)
    
answered by 31.10.2018 / 15:24
source
0

Use the convert to convert the value to the type of data you want, that is, your code should look like this,

 SELECT 
     SUM(AU.Tarifa_Diaria) AS [TOTAL],
     CONVERT(VARCHAR,MONTH(AO.fTermino)) AS [MES]
 FROM Arriendo_Autos AU INNER JOIN Arriendo_Solicitud AO
 ON AU.Patente = AO.Patente
 GROUP BY MONTH (AO.fTermino)

I hope it works for you

    
answered by 31.10.2018 в 13:31