IF OBJECT_ID('UFD_BUSCA_CONTA_BC_CONTAS') IS NOT NULL
	BEGIN
		DROP FUNCTION UFD_BUSCA_CONTA_BC_CONTAS
	END
	
GO	

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE   FUNCTION [dbo].[UFD_BUSCA_CONTA_BC_CONTAS](	@CD_EMP 		INT,
														@CD_CNT 		INT)
RETURNS @RS_RETURN TABLE(
		CD_CTB_CNT_RED	INT, 
		CD_CTB_CNT		VARCHAR(50), 
		DS_CNT			VARCHAR(100),
		NR_CNT			VARCHAR(50),
		TP_CNT			INT,
		TITULAR_CNT		VARCHAR(200))

	BEGIN
		
		INSERT INTO @RS_RETURN
			SELECT 
				ISNULL(CD_CTB_CNT_RED,0) AS CD_CTB_CNT_RED,
				ISNULL(CD_CTB_CNT,'')    AS CD_CTB_CNT,
				DS_CNT			,
				NR_CNT			,
				TP_CNT			,
				TITULAR
			FROM BC_CONTAS
			WHERE BC_CONTAS.CD_EMP 		= @CD_EMP
				  AND BC_CONTAS.CD_CNT 	= @CD_CNT			
		
		RETURN
		
	END
	
GO


