Hi @Glenn Mateus ,
Welcome to Microsoft Q&A!
I could not achieve your requirement using pivot/unpivot function after several attempts.
Is it possible using SQL Server PIVOT or UNPIVOT functions?
So it is NO
from my side. But you could wait for any possible solution from other experts.
Please refer below another solution using CROSS APPLY
:
create table #test
(MondayPercent decimal(5,2),
MondayStartDate datetime,
MondayUntilDate datetime,
TuesdayPercent decimal(5,2),
TuesdayStartDate datetime,
TuesdayUntilDate datetime,
WednesdayPercent decimal(5,2),
WednesdayStartDate datetime,
WednesdayUntilDate datetime,
ThursdayPercent decimal(5,2),
ThursdayStartDate datetime,
ThursdayUntilDate datetime)
insert into #test values
(-5.00,'2021-09-07','2022-12-31',-10.00,'2021-09-07','2022-12-31',-15.00,'2021-09-07','2022-12-31',-20.00,'2021-09-07','2022-12-31')
SELECT c.*
FROM #test
CROSS APPLY
(
VALUES
('MondayPercent',MondayPercent, MondayStartDate, MondayUntilDate),
('TuesdayPercent',TuesdayPercent, TuesdayStartDate, TuesdayUntilDate),
('WednesdayPercent',WednesdayPercent, WednesdayStartDate, WednesdayUntilDate),
('ThursdayPercent',ThursdayPercent, ThursdayStartDate, ThursdayUntilDate)
) c ([day],[value], startdate, untildate)
Output:
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
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.