; WITH BASE AS
(
SELECT EmpId,
EmpName,
ProcessName,
GroupCode,
PlannedDays,
ActualDays,
DelayedDays,
rnk = DENSE_RANK() OVER (PARTITION BY EmpID ORDER BY GroupCode)
FROM EmpProcessDetail)
SELECT
EmpId,
EmpName,
ProcessName,
GroupCode,
PlannedDays,
ActualDays,
DelayedDays,
x.TotalDelayDays
FROM
BASE b
CROSS...