0

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

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • 1
    Please share more details, like the "current code" and a **specific** question – Nico Haase Mar 23 '23 at 10:19
  • Please post your table and code here in text and not as image. Posting as a Text would attract answers – Tushar Mar 23 '23 at 10:21
  • Use [case ... when](https://www.w3schools.com/sql/func_mysql_case.asp) like [here](https://stackoverflow.com/a/26557209/21363224) – markalex Mar 23 '23 at 10:25
  • Does this answer your question? [How to get month name from number in mysql](https://stackoverflow.com/questions/16298896/how-to-get-month-name-from-number-in-mysql) – Ankit Bajpai Mar 23 '23 at 12:24

1 Answers1

0

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
marcothesane
  • 6,192
  • 1
  • 11
  • 21