George
George

Reputation: 263

lead function in sql not working as expected

I am using the following query to identify the newEndDate

enter image description here

But, the result i get is

enter image description here

Why am i not getting newEnddate for the last row ? please help

Upvotes: 0

Views: 1143

Answers (1)

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

You can use same column in lead() in last parameter :

lead(se.status_startdt, 1, se.status_startdt) over (partition by se.invoice_number order by se.status_startdt)

As per sample data this seems to be use of coalesce() :

coalesce(se.status_enddt, se.status_startdt)

Upvotes: 1

Related Questions