WeakLearner
WeakLearner

Reputation: 938

Alternatives to LAG() in sql server 2008

I asked this question:

create partition based on the difference between subsequent row indices in sql server 2012

I am just wondering how this could be done in an older version of sql server, say sql 2008 in which LAG is not a recognised function. Is there anyway to implement the lag function in older versions of SQL??

EDIT: perhaps I should have been more explicit, in the solution to the referred question, the lag function is used multiple times, is there a more efficient way than using multiple CTEs to get the same result?

Upvotes: 1

Views: 3600

Answers (1)

Set
Set

Reputation: 151

To achieve the same concept of LAG in older versions, you have to make left join on the same table for instance:

select *
from A a
left join B b on b.Column = a.Column - 1

Upvotes: 3

Related Questions