आप UNPIVOT
. का उपयोग कर सकते हैं फ़ंक्शन और एक CROSS APPLY
इसे पाने के लिए:
;with cte as
(
select col, value
from yourtable
unpivot
(
value
for col in ([Step X], [Step W], [Step A], [Step B], [Step Y])
) unpiv
)
select [Step X],
[Step W],
[Step A],
[Step B],
[Step Y],
d.col LastStep
from yourtable
cross apply
(
select c1.col
from cte c1
inner join
(
select max(value) MaxDate
from cte
) c2
on c1.value = c2.maxdate
) d
देखें SQL Fiddle with Demo