FIRST_VALUE() function syntax with an example in SQL Server

FIRST_VALUE() function syntax with an example in SQL Server 



·        This function returns the first value in an ordered set of values

Example:
The following example uses FIRST_VALUE to return the name of the product that is the least expensive in a given product category.
USE AdventureWorks2008R2;
GO
SELECT Name, ListPrice,
FIRST_VALUE (Name) OVER (ORDER BY ListPrice ASC) AS LeastExpensive
FROM Production.Product
WHERE ProductSubcategoryID = 37;

Result:
Name
ListPrice
LeastExpensive
Patch Kit/8 Patches
2.29
Patch Kit/8 Patches
Road Tire Tube
3.99
Patch Kit/8 Patches
Touring Tire Tube
4.99
Patch Kit/8 Patches
Mountain Tire Tube
4.99
Patch Kit/8 Patches
LL Road Tire
21.49
Patch Kit/8 Patches
ML Road Tire
24.99
Patch Kit/8 Patches
LL Mountain Tire
24.99
Patch Kit/8 Patches
Touring Tire
28.99
Patch Kit/8 Patches
ML Mountain Tire
29.99
Patch Kit/8 Patches
HL Road Tire
32.60
Patch Kit/8 Patches
HL Mountain Tire
35.00
Patch Kit/8 Patches




If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar