How can I transform the output of my "paymentMonth" column to display the months in text, in SQL?

29 views Asked by At

I would like the output of my "paymentMonth" column to display the months in text (January, February...) With my current code, what do i need to change/add for this to be achieved?

1

1

There are 1 answers

0
marcothesane On

This should work:

WITH
-- some of your input ..
indata(lastName,firstName,seller,paymentYear,paymentMonth,paymentTotal) AS (
          SELECT 'Jones','Barry'.   ,1504,2021,01,10549
UNION ALL SELECT 'Patterson','Steve',1216,2021,02,10223.8
UNION ALL SELECT 'Castillo','Pamela',1401,2021,08,53929.2
)
-- real query starts here ..
SELECT
  lastName
, firstName
, seller
, paymentyear
, date_format(
    cast(
        concat(concat(concat(paymentyear,'-'),paymentmonth),'-01') 
     as date
    )
  , '%M'
  ) as paymentmonth
, paymenttotal  
FROM indata;
lastName firstName seller paymentyear paymentmonth paymenttotal
Jones Barry 1504 2021 January 10549.0
Patterson Steve 1216 2021 February 10223.8
Castillo Pamela 1401 2021 August 53929.2