

ALTER FUNCTION [dbo].[CF_Reportes_User_Validar](@pId_Reporte VARCHAR(50), @pId_Usuario INT)
RETURNS TINYINT
AS
BEGIN

DECLARE @Cant INT

SET @Cant = (SELECT COUNT(*) FROM TAB_REPORTES_USERS WHERE ID_REPORTE = @pId_Reporte)

IF ISNULL(@Cant,0) = 0 RETURN 1

SET @Cant = (SELECT COUNT(*) FROM TAB_REPORTES_USERS WHERE ID_REPORTE = @pId_Reporte AND ID_USUARIO = @pId_Usuario)

IF ISNULL(@Cant,0) > 0 RETURN 1


SET @Cant = (SELECT COUNT(*) FROM TAB_REPORTES_USERS  WHERE ID_REPORTE = @pId_Reporte
             AND ID_USUARIO in (select UGrpNo from Seg_UserInGroup where UserNo = @pId_Usuario))
 
IF ISNULL(@Cant,0) > 0 RETURN 1


RETURN 0
END


 