Can values from a column in table A be used as headings in table B

  Kiến thức lập trình

I have created an output that looks like this and I also have a table (table A) that looks like the below

OUTPUT

Description MONTH1 MONTH2
xyz 2 5
abc 4 6

TABLE A

column no Month Name
1 April 2023
2 May 2023

the output was created using calculations like these:
COUNT (CASE WHEN a.column_no = 1 THEN a.ID END) AS MONTH1
COUNT (CASE WHEN a.column_no = 2 THEN a.ID END) AS MONTH2

Please is there anyways I can change ‘MONTH1’ to use the month name in table A instead without manually naming the column.
for example, in the output I would like month1 to say April 2023.

Can anyone help please.

I tried using a dynamic pivot but with no success

New contributor

Cynthia Tabi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT