USE [GrpInsurance]
GO
/****** Object:  StoredProcedure [dbo].[gproc_GetPermissionObject2]    Script Date: 02/28/2014 17:30:50 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[gproc_GetPermissionObject2]
@ObjectName varchar(50),
@IdUser varchar(4),
@FieldName varchar(20) OUTPUT,
@FieldValue varchar(250) OUTPUT
AS
DECLARE @Id_Permission varchar(5)
   SET @FieldName=''
   SET @FieldValue=''

   IF NOT EXISTS(SELECT T1.* FROM gPermission_Menu T1 INNER JOIN gMenu_Browse T3 
   ON T1.Id_Menu=T3.Id_Menu
   WHERE UPPER(T3.Script_Object)=Upper(@ObjectName)) RETURN 0

   SELECT @FieldName=T1.Field_Name, @FieldValue=T1.Field_Value  FROM gPermission_Menu T1 
   INNER JOIN gMenu_Browse T3 
   ON T1.Id_Menu=T3.Id_Menu WHERE UPPER(T3.Script_Object)=Upper(@ObjectName) 

   IF NOT EXISTS(SELECT T1.Id_Permission FROM gPermission_Menu T1 INNER JOIN gPermission_User T2
   ON T1.Id_Permission=T2.Id_Permission INNER JOIN gMenu_Browse T3 
   ON T1.Id_Menu=T3.Id_Menu WHERE UPPER(T3.Script_Object)=Upper(@ObjectName) AND T2.Id_User=@IdUser) 
   BEGIN
     SET @FieldValue=''
     -- SELECT @FieldName=T1.Field_Name, @FieldValue=T1.Field_Value  FROM gPermission_Menu T1 INNER JOIN gPermission_User T2
     -- ON T1.Id_Permission=T2.Id_Permission INNER JOIN gMenu_Browse T3 
     -- ON T1.Id_Menu=T3.Id_Menu WHERE UPPER(T3.Script_Object)=Upper(@ObjectName) AND T2.Id_User=@IdUser
   END
   RETURN 0
