AdventureWorks
dbo.ufnGetProductListPrice User Defined Function
Description
Scalar function returning the list price for a given product on a particular order date.
Properties
Creation Date08/01/2010 08:41
Encrypted
Ansi Nulls
Parameters
ParameterDirectionDescriptionData TypeSize
@ProductIDInInput parameter for the scalar function ufnGetProductListPrice. Enter a valid ProductID from the Production.Product table.int4
@OrderDateInInput parameter for the scalar function ufnGetProductListPrice. Enter a valid order date.datetime4
@RETURN_VALUEReturn Value money8
Objects that dbo.ufnGetProductListPrice depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.Flag datatypedbo.FlagUser Defined Data Type 2
dbo.Name datatypedbo.NameUser Defined Data Type 2
Production.Product tableProduction.ProductTableProducts sold or used in the manfacturing of sold products.1
Production.ProductCategory tableProduction.ProductCategoryTableHigh-level product categorization.3
Production.ProductListPriceHistory tableProduction.ProductListPriceHistoryTableChanges in the list price of a product over time.1
Production.ProductModel tableProduction.ProductModelTableProduct model classification.2
Production.ProductSubcategory tableProduction.ProductSubcategoryTableProduct subcategories. See ProductCategory table.2
Production.UnitMeasure tableProduction.UnitMeasureTableUnit of measure lookup table.2
Procedure Source Code
CREATE FUNCTION [dbo].[ufnGetProductListPrice](@ProductID [int], @OrderDate [datetime])
RETURNS [money] 
AS 

BEGIN
DECLARE @ListPrice money;
SELECT @ListPrice = plph.[ListPrice] 
FROM [Production].[Product] p 
INNER JOIN [Production].[ProductListPriceHistory] plph 
ON p.[ProductID] = plph.[ProductID] 
AND p.[ProductID] = @ProductID 
AND @OrderDate BETWEEN plph.[StartDate] AND COALESCE(plph.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices!
RETURN @ListPrice;
END;
See Also

Related Objects

dbo Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.