USE [Inversiones_20190620]
GO
/****** Object:  StoredProcedure [dbo].[SP_InventarioMaster]    Script Date: 6/23/2019 9:18:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		BC
-- Create date: 
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[SP_InventarioMaster] 
	-- Add the parameters for the stored procedure here

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	DECLARE @Inventario TABLE(
		CodInv varchar(20)
		,CodIF varchar(10)
		,Estado varchar(4)
		,CodEmpr varchar(10)
		,NombreManIF varchar(50)
		,CodManIF varchar(50)
		,CodEmis int
		,iCasaBanco varchar(1)
		,vCasaBanco varchar(10)
		,TipoMerc varchar(4)
		,CodCalRi varchar(8)
		,CodECalRi varchar(8)
		,ValorNominal numeric(18,6)

	)

	INSERT INTO @Inventario
	SELECT
		T0.CodInv
		,T0.CodIF
		,T0.DocEst
		,T0.CodEmpr
		,T0.NombreManIF
		,T0.CodManIF
		,T0.CodEmis	
		,NULL
		,NULL
		,T0.TipoMerc	
		,T0.CodCalRi
		,T0.CodECalRi
		,T1.MontoInv
	FROM [dbo].[INV0] T0
	INNER JOIN [dbo].[DAP0] T1 ON T0.CodInv=T1.CodInv

	INSERT INTO @Inventario
	SELECT
		T0.CodInv
		,T0.CodIF
		,T0.DocEst
		,T0.CodEmpr
		,T0.NombreManIF
		,T0.CodManIF
		,T0.CodEmis	
		,NULL
		,NULL
		,T0.TipoMerc	
		,T0.CodCalRi
		,T0.CodECalRi
		,T1.CuoPart
	FROM [dbo].[INV0] T0
INNER JOIN [dbo].[FINV] T1 ON T0.CodInv=T1.CodInv

	INSERT INTO @Inventario
	SELECT
		T0.CodInv
		,T0.CodIF
		,T0.DocEst
		,T0.CodEmpr
		,T0.NombreManIF
		,T0.CodManIF
		,T0.CodEmis	
		,NULL
		,NULL
		,T0.TipoMerc	
		,T0.CodCalRi
		,T0.CodECalRi
		,T1.ValTransC
	FROM [dbo].[INV0] T0
INNER JOIN [dbo].[ACC0] T1 ON T0.CodInv=T1.CodInv






SELECT * FROM @Inventario

END
