AdventureWorks
dbo.ufnGetStock User Defined Function
Description
Scalar function returning the quantity of inventory in LocationID 6 (Miscellaneous Storage)for a specified ProductID.
Properties
Creation Date08/01/2010 08:41
Encrypted
Ansi Nulls
Parameters
ParameterDirectionDescriptionData TypeSize
@ProductIDInInput parameter for the scalar function ufnGetStock. Enter a valid ProductID from the Production.ProductInventory table.int4
@RETURN_VALUEReturn Value int4
Objects that dbo.ufnGetStock depends on
 Database ObjectObject TypeDescriptionDep Level
dbo.Flag datatypedbo.FlagUser Defined Data Type 3
Production.Location tableProduction.LocationTableProduct inventory and manufacturing locations.2
dbo.Name datatypedbo.NameUser Defined Data Type 3
Production.Product tableProduction.ProductTableProducts sold or used in the manfacturing of sold products.2
Production.ProductCategory tableProduction.ProductCategoryTableHigh-level product categorization.4
Production.ProductInventory tableProduction.ProductInventoryTableProduct inventory information.1
Production.ProductModel tableProduction.ProductModelTableProduct model classification.3
Production.ProductSubcategory tableProduction.ProductSubcategoryTableProduct subcategories. See ProductCategory table.3
Production.UnitMeasure tableProduction.UnitMeasureTableUnit of measure lookup table.3
Procedure Source Code
CREATE FUNCTION [dbo].[ufnGetStock](@ProductID [int])
RETURNS [int] 
AS 

BEGIN
DECLARE @ret int;

SELECT @ret = SUM(p.[Quantity]) 
FROM [Production].[ProductInventory] p 
WHERE p.[ProductID] = @ProductID 
AND p.[LocationID] = '6'; -- Only look at inventory in the misc storage

IF (@ret IS NULL) 
SET @ret = 0

RETURN @ret
END;
See Also

Related Objects

dbo Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.