Solved

lag function

Posted on 2009-04-09
3
950 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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