Consider the below
Id Nums
1 10
2 20
3 30
4 40
5 50
The expected output
Id CurrentValue PreviousValue
1 10 Null
2 20 10
3 30 20
4 40 30
5 50 40
I am trying with the below but no luck
;With Cte(Id,CurrValue,PrevValue) As
(
Select
Id
,CurrentValue = Nums
,PreviousValue = Null
From @t Where Id = 1
Union All
Select
t.Id
,c.CurrValue
,c.PrevValue
From Cte c
Join @t t On c.Id <= t.Id + 1
)
Select *
From Cte
Help needed