USE [GrpInsurance]
GO
/****** Object:  StoredProcedure [dbo].[gproc_GetPermissionObject2]    Script Date: 02/28/2014 09:23:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE 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
 

SELECT 
  T1.*,
  T3.*
FROM 
  gPermission_Menu T1 INNER JOIN 
  gMenu_Browse T3 ON T1.Id_Menu=T3.Id_Menu
WHERE UPPER(T3.Script_Object)=Upper('view_Polis')

SELECT * FROM gPermission_Menu
SELECT * FROM gMenu_Browse


SELECT T1.Field_Name, 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('view_Peserta') 

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('view_Peserta') AND T2.Id_User='NUK'

SELECT T1.Field_Name, 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('view_Peserta') AND T2.Id_User='DUR'

SELECT TOP 50 * FROM view_Peserta

SELECT * FROM Perusahaan WHERE No_Prs IN ('2006.1398', '2001.0451', '2001.0081', '2008.3958', '2007.2170', '2007.7217', '2007.7216', '2006.1999', '2006.2002')