Reputation: 5
Been trying with the following query but i'm getting constant difference
with cte as
(
select businessentityid,nationalidnumber,SickLeaveHours,LAG(sickleavehours) over (order by businessentityid) as PreviousRow
from HumanResources.Employee
)
select *,DIFFERENCE(sickleavehours,cte.previousrow) from cte
Upvotes: 0
Views: 111
Reputation: 31239
Can you just do this?:
with cte as
(
select businessentityid,nationalidnumber,SickLeaveHours,LAG(sickleavehours) over (order by businessentityid) as PreviousRow
from HumanResources.Employee
)
select *, sickleavehours - cte.previousrow as difference from cte
Upvotes: 1