/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
USE [CalendarOrders] GO /****** Object: StoredProcedure [dbo].[ItemLookupWithTotals_Select] Script Date: 02/05/2009 15:09:27 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,siqing Li> -- ============================================= ALTER PROCEDURE [dbo].[ItemLookupWithTotals_Select] --@ReturnValue int output AS BEGIN SET NOCOUNT ON; SELECT ItemId, SUM(Qty) AS Total INTO #TotalTemp FROM BulkItems WHERE PurchaseDate IS NULL GROUP BY ItemId DECLARE @TempItems TABLE (ItemId INT, Category VARCHAR(25), MFG VARCHAR(50), Description VARCHAR(100), SIZE VARCHAR(50), Price money, Total INT DEFAULT 0) INSERT INTO @TempItems (ItemID, Category, MFG, Description, SIZE, Price) SELECT ItemID, Category, MFG, Description, SIZE, Price FROM ItemLookup UPDATE @TempItems SET a.Total = b.Total FROM @TempItems AS a JOIN #TotalTemp AS b ON a.ItemID = b.ItemID --SELECT * FROM @TempItems SELECT ItemID, Category, MFG, Description, SIZE, Price,Price*Total AS Amount FROM @TempItems DROP TABLE #TotalTemp --SELECT @ReturnValue = SCOPE_IDENTITY() --RETURN @ReturnValue END --Execute ItemLookupWithTotals_Select