79720568

Date: 2025-07-30 21:51:45
Score: 1.5
Natty:
Report link

Update for SQL Server 2022 (16.x) and later: LAG function can ignore NULLs.

LAG (scalar_expression [ , offset ] [ , default ] ) [ IGNORE NULLS | RESPECT NULLS ]
    OVER ( [ partition_by_clause ] order_by_clause )

Default value is RESPECT NULLS. So username12345 source solution will work as he expected after adding IGNORE NULLS to the LAG function.

MS docs: https://learn.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql?view=sql-server-ver16

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Alex