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


CREATE FUNCTION [dbo].[CF_Menu_Favorito](@pUsuario INT, @pMeu INT)
RETURNS SMALLINT
AS
BEGIN

DECLARE @Favorito INT


SET @Favorito = (SELECT Id_Favorito FROM Seg_User_Fav WHERE Id_Usuario=@pUsuario AND Id_Menu=@pMeu)


RETURN ISNULL(@Favorito, 0)
END

/*
select dbo.CF_Menu_Favorito(1,524)
*/