I need to Pivot date/month rows to column.
I have a set of month rows. The number of rows will vary and is not fixed(could be up to 60 months i.e. 5+ years). Need to convert them into columns.
FROM THIS
Month Department Job FTE
AUG 2023 1017 Sourcing Consultant. 1
SEP 2023 1017 Sourcing Consultant. 1
OCT 2023 1017 Sourcing Consultant. 1
NOV 2023 1017 Sourcing Consultant. 1
DEC 2023 1017 Sourcing Consultant. 1
JAN 2024 1017 Sourcing Consultant. 1
FEB 2024 1017 Sourcing Consultant. 1
MAR 2024 1017 Sourcing Consultant. 1
_TO THIS _
AUG 2023 SEP 2023 OCT 2023 NOV 2023 DEC 2023 JAN 2024 FEB 2024 MAR 2024
1017 Sourcing Consultant. 1 1 1 1 1 1 1 1
Best Answer
-
marcothesane - Select Field - Administrator
If you want the stored procedure, shout. I'll try to paste its source here.
0
Answers
The only way I can see this - without the use of a Stored Procedure that will actually generate the statement I wrote by hand out of the very yearmonth names you use in "Month" - is what you can see below:
Hi Macrothesane.
Thanks for answering my query. Yes, it does answer my question. Only problem is I need to go in every year and tweak the query/code to remove prior year 12 months and add new 5th year's 12 month. I was hoping to avoid that annual change. But still thanks for responding!!!
Can the following help you avoid annual changes?
Hi skulkarvertica,
One thing you didn't mention is how the months range is moving.
If it's related to the current month, then you won't have to rewrite the query using this way:
You won't have the proper name for the columns, but that should be usable anyway.