SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Getting LEAD and LAG values manually

By Sheraz Mirza,

Getting Previous is next values is always a need for any database professional, specially Analyst and Developers, SQL Server provide built in Functions for this purpose which are introduced in SQL Server 2012, This Script is useful to get same results in Earlier versions like 2008, 2008R2 etc.

We can get  our result in three easy steps

1.        create a Table and insert some dummy records for Demo.

2.       Inserting Dummy Records

3. Query to see LEAD and LAG Values

Here is your Previous Values /LAG Function Result

and here is your Next Values /LEAD Function Result

See you next time guys .....

Total article views: 707 | Views in the last 30 days: 8
 
Related Articles
FORUM

Return result of dynamic query from function

Return result of dynamic query from function

FORUM

MDX RANK function: unexpected results

I'm getting a wrong result when using the RANK function

FORUM

"function"

"function"

FORUM

Hashbytes function returning unexpected results

SQL 2005 HASHBYTES UNEXPECTED RESULTS

FORUM

Function

Dynamic Function

 
Contribute