Skip to content
Advertisement

Tag: lead

SQL Server LEAD function

I am getting the following error when I run this query. [42S22] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name ‘NEXT_DATE’. (207) (SQLExecDirectW) This is a leetcode medium question 550. Game Play Analysis IV. I wanted to know why it can’t identify the column NEXT_DATE here and what am I missing? Thanks! Answer The problem is in this CTE:

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? Answer

Advertisement