Skip to content
Advertisement

SQL Server Lag and Lead

I’m using SQL Server 2014.

I have a table:

I have some data:

If I perform a LAG and LEAD using the below for one Job, I get the desired result:

Result:

Notice the NULL for the first FromActionCode and LastToCode, which is correct.

However, If I look at all records, it messes it up:

What am I missing?

Advertisement

Answer

Did you try with PARTITION

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement