USE [Inversiones_20190610]
GO
/****** Object:  StoredProcedure [dbo].[INV_SP_DetalleIngresos]    Script Date: 6/11/2019 9:51:05 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		BC
-- Create date: 
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[INV_SP_DetalleIngresos] 
	-- Add the parameters for the stored procedure here
	@CodInv varchar(20)
	,@IngresoID int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT TOP 1
	T1.CodInv
	,INV.CodEmpr
	,(SELECT S0.Descrip FROM [dbo].[EMPR] S0 WHERE S0.CodEmpr=INV.CodEmpr) 'Empresa'
	,INV.CodEmis
	,(SELECT S0.Descrip FROM [dbo].[EMIS] S0 WHERE S0.CodEmis= INV.CodEmis) 'Emisor'
	,INV.CodIF
	,(SELECT S0.Descrip FROM [dbo].[INFI] S0 WHERE S0.CodIF=INV.CodIF ) 'Instrumento'
	,INV.CodManIF
	,INV.NombreManIF
	,INV.CodPais
	,(SELECT S0.Descrip FROM [dbo].[PAIS] S0 WHERE S0.CodPais=INV.CodPais ) 'Pais'
	,INV.NumManInv
	,T1.Correlativo
	,T1.IngresoNeto
	,INV.CodECalRi
	,(SELECT S0.Descrip FROM [dbo].[ECALRI] S0 WHERE S0.CodECalRi=INV.CodECalRi ) 'Calificadora'

FROM [dbo].[ACC1] T1
INNER JOIN [dbo].[ACC0] T0 ON T0.CodInv=T1.CodInv
INNER JOIN [dbo].[INV0] INV ON INV.CodInv = T1.CodInv
WHERE 1=1
AND T1.CodInv=@CodInv
AND T1.Correlativo=@IngresoID
END
