IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[CF_SCA_IdAcceso]') 
                   and [type] = 'FN')
BEGIN
    DROP FUNCTION dbo.CF_SCA_IdAcceso
END
GO

CREATE FUNCTION [dbo].[CF_SCA_IdAcceso](@pId_Controlador	SMALLINT)
RETURNS SMALLINT
AS
BEGIN
DECLARE @Id_Acceso		SMALLINT

SET @Id_Acceso = (SELECT ISNULL(Id_Acceso, 0) FROM Cd_Controladores WHERE Id_Controlador = @pId_Controlador)

RETURN ISNULL(@Id_Acceso, 0)

END