"usp_ShoppingCartTotal" Stored Procedure

Description:

This stored procedure computes the total dollar amount of all the items in the given CartID. Used on the display of the Shopping Cart screen.

Definition:
CREATE Procedure usp_ShoppingCartTotal
(
    @CartID    nvarchar(50),
	@Culture nvarchar(10),
    @TotalCost nvarchar(20) OUTPUT

)
AS

SELECT 
    @TotalCost = dbo.ConvertCurrency(SUM(P.ListPrice * SCI.Quantity), @Culture).ToString()

FROM 
    Sales.ShoppingCartItem as SCI,
    Production.Product as P

WHERE
    SCI.ShoppingCartID = @CartID
  AND
    P.ProductID = SCI.ProductID;

Database Tables Used:

ShoppingCartItem:   The ShoppingCartItem table keeps track of the items a user has purchased.  Its primary key is the ShoppingCartItemID field.  The ShoppingCartID is a string which is used to identify the user who owns the basket of items.  There is a many to one relationship between the ShoppingCartItem table and the Product table.  Note that if not Quantity is supplied, a default of 1 is entered.

Product:  The Product table contains the core information about all of the items for sale on the Adventure Works Cycles web site. Its primary key is the ProductID identity field.