Link to home
Start Free TrialLog in
Avatar of qadsam
qadsam

asked on

lag function

I am trying to accomplish lag function, over and last value, first value in sql server 2005.

Can you please help.
Query from oracle i wanted to convert to sql server
100*((reads- nvl(lag(reads,1)over(order by snap_id),reads)) /
    (last_value(reads)over(order by 1)-first_value(reads)over(order by 1))) Reads

Thanks,
sam
100*((reads- nvl(lag(reads,1)over(order by snap_id),reads)) /
    (last_value(reads)over(order by 1)-first_value(reads)over(order by 1))) PRD,

Open in new window

Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Hi qadsam,

As far as I am aware, SQL Server has not implemented the LEAD or LAG functions.  This might help http://rafael-salas.blogspot.com/2008/05/t-sql-lead-and-lag-functions.html 

lwadwell
ASKER CERTIFIED SOLUTION
Avatar of sameer2010
sameer2010
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qadsam
qadsam

ASKER

Solution found
Thanks,