hi
i want get Inventory by subtracting the amount of incoming and outgoing goods with stored procedure ,
i try get inventory from two parameter : @income - @outcome = inventory
USE [Bonakdar_DB]GO/****** Object: StoredProcedure [dbo].[SP_Inventory] Script Date: 06/11/2015 11:35:36 ?.? ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[SP_Inventory]ASDECLARE @income INT = (select sum(Quantity) from View_Inventory where [Type_Bool] = 1 group by [Commodity_Id])DECLARE @outcome INT = (select sum(Quantity) from View_Inventory where [Type_Bool] = 0 group by [Commodity_Id])DECLARE @uotput TABLE ( commo_Id int, nam nvarchar(20), quant int, uni nvarchar(50), typ nvarchar(10), dat datetime )INSERT @uotput SELECT [Commodity_Id], [Name], [Quantity], [Unit], [Type], [Date] FROM View_InventoryBEGINSET NOCOUNT ON;SELECT commo_Id, nam, quant, (@income - @outcome) AS inventory, uni, typ, dat FROM @uotput ORDER BY dat ENDbut display output table without inventory parameter and send error :
Msg 512, Level 16, State 1, Procedure SP_Inventory, Line 3
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Msg 512, Level 16, State 1, Procedure SP_Inventory, Line 4
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
(4 row(s) affected)

Replies
Know the answer? Post it — somebody with the same question will find it here.