IF OBJECT_ID('dbo.fn_fco_cod_super') IS NOT NULL
    DROP FUNCTION dbo.fn_fco_cod_super
GO
CREATE FUNCTION dbo.fn_fco_cod_super
(
    @pch_tipo char(3),
    @pch_dato char(10)
)
RETURNS char(6)
AS
BEGIN
    DECLARE @vch_codigo char(6)

    SELECT @vch_codigo = LEFT(LTRIM(cod_super), 6)
    FROM fco_administradoras
    WHERE codigo = @pch_dato
      AND tipo = @pch_tipo

    RETURN ISNULL(@vch_codigo, ' ')
END
GO
GRANT EXECUTE ON dbo.fn_fco_cod_super TO PUBLIC
GO
