if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[QX_RIGHT]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[QX_RIGHT]
GO

create view dbo.QX_RIGHT as
    select distinct
        cast(PR.SECURITY_ID as VARCHAR) + '_' + FR.FORM_ID as PKEY,
        PR.SECURITY_ID,
        PR.PERMISSION_ID,
        FC.FOCUS_ID,
        SF.SUBFOCUS_ID,
        TB.TAB_ID,
        FR.FORM_ID,
        FS.ACCESS_LEVEL,
        SC.NAME AS ROLE
    from
        QX_FOCUS FC
        JOIN    QX_SUBFOCUS SF on (FC.FOCUS_ID = SF.FOCUS_ID)
        JOIN    QX_TAB TB  on (SF.SUBFOCUS_ID = TB.SUBFOCUS_ID)
        JOIN    QX_FORM FR on (TB.TAB_ID = FR.TAB_ID)
        LEFT OUTER JOIN	   QX_FORMSET FS    on (FR.FORM_ID = FS.FORM_ID)
        LEFT OUTER JOIN    QX_PERMISSION PR on (FS.PERMISSION_ID = PR.PERMISSION_ID)
        LEFT OUTER JOIN    QX_SECURITY SC   on (PR.SECURITY_ID = SC.SECURITY_ID)
go

UPDATE QX_SYS_PROP SET PROP_VAL = '013' WHERE (PROP_ID = 'DB_CORE_VERSION');