Solved

lag function

Posted on 2009-04-09
3
948 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:qadsam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 24112467
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
0
 
LVL 13

Accepted Solution

by:
sameer2010 earned 500 total points
ID: 26284238
0
 

Author Closing Comment

by:qadsam
ID: 31568552
Solution found
Thanks,
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question