I need to store the previous value in a column till there is a change and in case of change it would retain the new value
Example
Input
-------
ID Name Stdt EndDt
1 A 20/01/2019 20/02/2019
1 B 20/02/2019 20/03/2019
1 C 20/03/2019 15/05/2019
1 C 15/05/2019 16/05/2019
1 C 16/05/2019 19/06/2019
1 C 19/06/2019 15/07/2019
1 A 15/07/2019 NULL
Output
----------
ID Name Stdt EndDt Previous Name
1 A 20/01/2019 20/02/2019 NULL
1 B 20/02/2019 20/03/2019 A
1 C 20/03/2019 15/05/2019 B
1 C 15/05/2019 16/05/2019 B
1 C 16/05/2019 19/06/2019 B
1 C 19/06/2019 15/07/2019 B
1 A 15/07/2019 NULL C
Tried preceding and self joins but those are limited to know number of changes (like name can remain constant for N times) but need more dynamic
You need nested Window functions: