Hi @Cholotron ,
Welcome to Microsoft Q&A!
Actually it is a little difficulty to write a query to get your expected output using TSQL.
You could check whether there is a better way using Excel, SSIS, SSRS or other tool.
In TSQL, I took a lot of time and could perform as below. You could check whether it is a little helpful to you.
;with cte as (
select emp_id,day_date,umc_sh,umc_vac,umc_bank,umc_over
,'umc_sh_' + CONVERT(nvarchar(30), day_date, 126) umc_sh_name
,'umc_vac_' + CONVERT(nvarchar(30), day_date, 126) umc_vac_name
,'umc_bank_' +CONVERT(nvarchar(30), day_date, 126) umc_bank_name
,'umc_over_' + CONVERT(nvarchar(30), day_date, 126) umc_over_name
from [tc_shiftx]
where week_id=112 and emp_group='MANF'
)
select emp_id
,max([umc_sh_2021-01-24]) [umc_sh_2021-01-24]
,max([umc_vac_2021-01-24]) [umc_vac_2021-01-24]
,max([umc_bank_2021-01-24]) [umc_bank_2021-01-24]
,max([umc_over_2021-01-24]) [umc_over_2021-01-24]
,max([umc_sh_2021-01-25]) [umc_sh_2021-01-25]
,max([umc_vac_2021-01-25]) [umc_vac_2021-01-25]
,max([umc_bank_2021-01-25]) [umc_bank_2021-01-25]
,max([umc_over_2021-01-25]) [umc_over_2021-01-25]
,max([umc_sh_2021-01-26]) [umc_sh_2021-01-26]
,max([umc_vac_2021-01-26]) [umc_vac_2021-01-26]
,max([umc_bank_2021-01-26]) [umc_bank_2021-01-26]
,max([umc_over_2021-01-26]) [umc_over_2021-01-26]
,max([umc_sh_2021-01-27]) [umc_sh_2021-01-27]
,max([umc_vac_2021-01-27]) [umc_vac_2021-01-27]
,max([umc_bank_2021-01-27]) [umc_bank_2021-01-27]
,max([umc_over_2021-01-27]) [umc_over_2021-01-27]
,max([umc_sh_2021-01-28]) [umc_sh_2021-01-28]
,max([umc_vac_2021-01-28]) [umc_vac_2021-01-28]
,max([umc_bank_2021-01-28]) [umc_bank_2021-01-28]
,max([umc_over_2021-01-28]) [umc_over_2021-01-28]
,max([umc_sh_2021-01-29]) [umc_sh_2021-01-29]
,max([umc_vac_2021-01-29]) [umc_vac_2021-01-29]
,max([umc_bank_2021-01-29]) [umc_bank_2021-01-29]
,max([umc_over_2021-01-29]) [umc_over_2021-01-29]
,max([umc_sh_2021-01-30]) [umc_sh_2021-01-30]
,max([umc_vac_2021-01-30]) [umc_vac_2021-01-30]
,max([umc_bank_2021-01-30]) [umc_bank_2021-01-30]
,max([umc_over_2021-01-30]) [umc_over_2021-01-30]
,max([umc_sh_2021-01-31]) [umc_sh_2021-01-31]
,max([umc_vac_2021-01-31]) [umc_vac_2021-01-31]
,max([umc_bank_2021-01-31]) [umc_bank_2021-01-31]
,max([umc_over_2021-01-31]) [umc_over_2021-01-31]
,max([umc_sh_2021-02-01]) [umc_sh_2021-02-01]
,max([umc_vac_2021-02-01]) [umc_vac_2021-02-01]
,max([umc_bank_2021-02-01]) [umc_bank_2021-02-01]
,max([umc_over_2021-02-01]) [umc_over_2021-02-01]
,max([umc_sh_2021-02-02]) [umc_sh_2021-02-02]
,max([umc_vac_2021-02-02]) [umc_vac_2021-02-02]
,max([umc_bank_2021-02-02]) [umc_bank_2021-02-02]
,max([umc_over_2021-02-02]) [umc_over_2021-02-02]
,max([umc_sh_2021-02-03]) [umc_sh_2021-02-03]
,max([umc_vac_2021-02-03]) [umc_vac_2021-02-03]
,max([umc_bank_2021-02-03]) [umc_bank_2021-02-03]
,max([umc_over_2021-02-03]) [umc_over_2021-02-03]
,max([umc_sh_2021-02-04]) [umc_sh_2021-02-04]
,max([umc_vac_2021-02-04]) [umc_vac_2021-02-04]
,max([umc_bank_2021-02-04]) [umc_bank_2021-02-04]
,max([umc_over_2021-02-04]) [umc_over_2021-02-04]
,max([umc_sh_2021-02-05]) [umc_sh_2021-02-05]
,max([umc_vac_2021-02-05]) [umc_vac_2021-02-05]
,max([umc_bank_2021-02-05]) [umc_bank_2021-02-05]
,max([umc_over_2021-02-05]) [umc_over_2021-02-05]
,max([umc_sh_2021-02-06]) [umc_sh_2021-02-06]
,max([umc_vac_2021-02-06]) [umc_vac_2021-02-06]
,max([umc_bank_2021-02-06]) [umc_bank_2021-02-06]
,max([umc_over_2021-02-06]) [umc_over_2021-02-06]
from (
select * from cte s
pivot
(max(umc_sh)
for umc_sh_name in([umc_sh_2021-01-24],[umc_sh_2021-01-25],[umc_sh_2021-01-26],[umc_sh_2021-01-27],[umc_sh_2021-01-28],[umc_sh_2021-01-29],[umc_sh_2021-01-30],[umc_sh_2021-01-31],[umc_sh_2021-02-01],[umc_sh_2021-02-02],[umc_sh_2021-02-03],[umc_sh_2021-02-04],[umc_sh_2021-02-05],[umc_sh_2021-02-06])) p
pivot
(max(umc_vac)
for umc_vac_name in([umc_vac_2021-01-24],[umc_vac_2021-01-25],[umc_vac_2021-01-26],[umc_vac_2021-01-27],[umc_vac_2021-01-28],[umc_vac_2021-01-29],[umc_vac_2021-01-30],[umc_vac_2021-01-31],[umc_vac_2021-02-01],[umc_vac_2021-02-02],[umc_vac_2021-02-03],[umc_vac_2021-02-04],[umc_vac_2021-02-05],[umc_vac_2021-02-06])) p1
pivot
(max(umc_bank)
for umc_bank_name in([umc_bank_2021-01-24],[umc_bank_2021-01-25],[umc_bank_2021-01-26],[umc_bank_2021-01-27],[umc_bank_2021-01-28],[umc_bank_2021-01-29],[umc_bank_2021-01-30],[umc_bank_2021-01-31],[umc_bank_2021-02-01],[umc_bank_2021-02-02],[umc_bank_2021-02-03],[umc_bank_2021-02-04],[umc_bank_2021-02-05],[umc_bank_2021-02-06])) p2
pivot
(max(umc_over)
for umc_over_name in([umc_over_2021-01-24],[umc_over_2021-01-25],[umc_over_2021-01-26],[umc_over_2021-01-27],[umc_over_2021-01-28],[umc_over_2021-01-29],[umc_over_2021-01-30],[umc_over_2021-01-31],[umc_over_2021-02-01],[umc_over_2021-02-02],[umc_over_2021-02-03],[umc_over_2021-02-04],[umc_over_2021-02-05],[umc_over_2021-02-06])) p3
) a
group by emp_id
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.