User281315223 posted
If I remember correctly, the inner query within a PIVOT doesn't support ordering, however since you are simply querying the results _from_ the PIVOT operation, you should be able to order by in your outer select statement:
SELECT *
FROM (SELECT CurrCode,
YEARNO,
Monthno,
TOTALAMOUNT
FROM [dbo].[ML_tbl_Analaysis]
WHERE Currcode =@CURRCODE) tbl
PIVOT (sum(TOTALAMOUNT) FOR [yearno] IN ([2016],[2017],[2018],[2019], [2020],[2021],[2022],[2023],[2024],[2025])) AS pivot_table
ORDER BY Monthno