Solved

lag function

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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