0
Answer

Inventory by subtracting the amount of incoming and outgoing

Ask a question
ghasem deh

ghasem deh

8y
458
1
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 ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_Inventory]
AS
DECLARE @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_Inventory
BEGIN
SET NOCOUNT ON;
SELECT commo_Id, nam, quant, (@income - @outcome) AS inventory, uni, typ, dat FROM @uotput ORDER BY dat
END
 
but 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)