Hi @SM
Try this query.
;with CTE as(
select * from Items
unpivot(Quantity for date in (Nov2019,Dec2019,Jan2020,Feb2020,Mar2020)) t)
select id,Branch,Name,Code,right(date,4) as Year,
case left(date,3) when 'Nov' then 11
when 'Dec' then 12
when 'Jan' then 1
when 'Feb' then 2
when 'Mar' then 3 end as Month,Quantity
from CTE;
Output:
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.