Solved

lag function

Posted on 2009-04-09
3
938 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
3 Comments
 
LVL 25

Expert Comment

by:lwadwell
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

by:qadsam
Comment Utility
Solution found
Thanks,
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now