﻿-- =============================================
-- Description:	Schema View-kat generáló script
-- =============================================

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF OBJECT_ID('dbo.sp_Global_CreateSchemaViews') IS NOT NULL
BEGIN
  DROP PROCEDURE [dbo].[sp_Global_CreateSchemaViews]
END
GO

CREATE PROCEDURE [dbo].[sp_Global_CreateSchemaViews]
		@IntezmenyId int,
		@IntezmenyAzonosito nvarchar(30),
		@TanevId int
AS
BEGIN
DECLARE @IntezmenyTemplate nvarchar(50) = 'KR_'+@IntezmenyAzonosito
DECLARE @Schema nvarchar(50) = @IntezmenyTemplate+'_Schema'
DECLARE @SchemaUser nvarchar(50) = @IntezmenyTemplate + '_user'
DECLARE @AktivTanev nvarchar(500)
DECLARE @Sql nvarchar(max)

/*============================================================================*/
/* View : T_NATKERDOIV                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NATKERDOIV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NATKERDOIV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NATKERDOIV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NATKERDOIV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NATKERDOIV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NATKERDOIV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NATKERDOIV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATKERDOIV
        AS
        SELECT *
        FROM dbo.T_NATKERDOIV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NATKERDOIV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATKERDOIV_OSSZES
        AS
        SELECT *
        FROM dbo.T_NATKERDOIV
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NATKERDOIV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATKERDOIV
        AS
        SELECT *
        FROM dbo.T_NATKERDOIV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NATKERDOIV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATKERDOIV_OSSZES
        AS
        SELECT *
        FROM dbo.T_NATKERDOIV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTEKELESMONDATBANK                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTEKELESMONDATBANK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESMONDATBANK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTEKELESMONDATBANK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESMONDATBANK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESMONDATBANK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESMONDATBANK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTEKELESMONDATBANK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMONDATBANK
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMONDATBANK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESMONDATBANK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMONDATBANK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMONDATBANK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTEKELESMONDATBANK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMONDATBANK
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMONDATBANK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESMONDATBANK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMONDATBANK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMONDATBANK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KOZOSSEGISZOLGALATTIPUS                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KOZOSSEGISZOLGALATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KOZOSSEGISZOLGALATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KOZOSSEGISZOLGALATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS
        AS
        SELECT *
        FROM dbo.T_KOZOSSEGISZOLGALATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KOZOSSEGISZOLGALATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KOZOSSEGISZOLGALATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KOZOSSEGISZOLGALATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS
        AS
        SELECT *
        FROM dbo.T_KOZOSSEGISZOLGALATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KOZOSSEGISZOLGALATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZOSSEGISZOLGALATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KOZOSSEGISZOLGALATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGTEREMFOGLALTSAG                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGTEREMFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTEREMFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGTEREMFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTEREMFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTEREMFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTEREMFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGTEREMFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREMFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTEREMFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGTEREMFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREMFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTEREMFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGTEREMFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREMFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTEREMFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGTEREMFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREMFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTEREMFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGFOGLALKOZASFOGLALTSAG                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZASFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZASFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGFOGLALKOZASFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZASFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZASFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZASFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGFOGLALKOZASFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZASFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZASFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZASFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZASFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGEXPORTORAREND                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGEXPORTORAREND', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGEXPORTORAREND'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGEXPORTORAREND_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGEXPORTORAREND_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGEXPORTORAREND' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGEXPORTORAREND' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGEXPORTORAREND */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGEXPORTORAREND
        AS
        SELECT *
        FROM dbo.T_OGEXPORTORAREND
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGEXPORTORAREND_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGEXPORTORAREND_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGEXPORTORAREND
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGEXPORTORAREND */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGEXPORTORAREND
        AS
        SELECT *
        FROM dbo.T_OGEXPORTORAREND
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGEXPORTORAREND_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGEXPORTORAREND_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGEXPORTORAREND'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGORARENDIORA                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGORARENDIORA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGORARENDIORA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGORARENDIORA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGORARENDIORA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGORARENDIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGORARENDIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGORARENDIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGORARENDIORA
        AS
        SELECT *
        FROM dbo.T_OGORARENDIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGORARENDIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGORARENDIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGORARENDIORA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGORARENDIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGORARENDIORA
        AS
        SELECT *
        FROM dbo.T_OGORARENDIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGORARENDIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGORARENDIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGORARENDIORA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGINTEZMENYFOGLALTSAG                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGINTEZMENYFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGINTEZMENYFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGINTEZMENYFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGINTEZMENYFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGINTEZMENYFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGINTEZMENYFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGINTEZMENYFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGINTEZMENYFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGINTEZMENYFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGINTEZMENYFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGINTEZMENYFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGINTEZMENYFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGINTEZMENYFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGINTEZMENYFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGINTEZMENYFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGINTEZMENYFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGINTEZMENYFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGINTEZMENYFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGGENERATORALAP                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGGENERATORALAP', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGGENERATORALAP'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGGENERATORALAP_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGGENERATORALAP_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGGENERATORALAP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGGENERATORALAP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGGENERATORALAP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGGENERATORALAP
        AS
        SELECT *
        FROM dbo.T_OGGENERATORALAP
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGGENERATORALAP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGGENERATORALAP_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGGENERATORALAP
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGGENERATORALAP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGGENERATORALAP
        AS
        SELECT *
        FROM dbo.T_OGGENERATORALAP
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGGENERATORALAP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGGENERATORALAP_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGGENERATORALAP'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGOSZTALYCSOPORTFOGLALTSAG                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGOSZTALYCSOPORTFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGOSZTALYCSOPORTFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGOSZTALYCSOPORTFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORTFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORTFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGOSZTALYCSOPORTFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORTFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORTFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORTFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGFOGLALTSAGTIPUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGFOGLALTSAGTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALTSAGTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGFOGLALTSAGTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALTSAGTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALTSAGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALTSAGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGFOGLALTSAGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALTSAGTIPUS
        AS
        SELECT *
        FROM dbo.T_OGFOGLALTSAGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALTSAGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALTSAGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALTSAGTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGFOGLALTSAGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALTSAGTIPUS
        AS
        SELECT *
        FROM dbo.T_OGFOGLALTSAGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALTSAGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALTSAGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALTSAGTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGFOGLALKOZAS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGFOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGFOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGTANTARGYFOGLALTSAG                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGTANTARGYFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTANTARGYFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGTANTARGYFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTANTARGYFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTANTARGYFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTANTARGYFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGTANTARGYFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANTARGYFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTANTARGYFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGTANTARGYFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANTARGYFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTANTARGYFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGTANTARGYFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANTARGYFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTANTARGYFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGTANTARGYFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANTARGYFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTANTARGYFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGFOGLALKOZAS_TEREM                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZAS_TEREM', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZAS_TEREM'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGFOGLALKOZAS_TEREM_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGFOGLALKOZAS_TEREM_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZAS_TEREM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGFOGLALKOZAS_TEREM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGFOGLALKOZAS_TEREM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_TEREM
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS_TEREM
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZAS_TEREM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_TEREM_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS_TEREM
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGFOGLALKOZAS_TEREM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_TEREM
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS_TEREM
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGFOGLALKOZAS_TEREM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGFOGLALKOZAS_TEREM_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGFOGLALKOZAS_TEREM'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGOSZTALYCSOPORT                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGOSZTALYCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGOSZTALYCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGOSZTALYCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGOSZTALYCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGOSZTALYCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGOSZTALYCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGTEREM_TANTARGY                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGTEREM_TANTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTEREM_TANTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGTEREM_TANTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTEREM_TANTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTEREM_TANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTEREM_TANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGTEREM_TANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREM_TANTARGY
        AS
        SELECT *
        FROM dbo.T_OGTEREM_TANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGTEREM_TANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREM_TANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTEREM_TANTARGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGTEREM_TANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREM_TANTARGY
        AS
        SELECT *
        FROM dbo.T_OGTEREM_TANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGTEREM_TANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTEREM_TANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTEREM_TANTARGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OGTANARFOGLALTSAG                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OGTANARFOGLALTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTANARFOGLALTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGTANARFOGLALTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGTANARFOGLALTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTANARFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OGTANARFOGLALTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OGTANARFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANARFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTANARFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGTANARFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANARFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTANARFOGLALTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGTANARFOGLALTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANARFOGLALTSAG
        AS
        SELECT *
        FROM dbo.T_OGTANARFOGLALTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OGTANARFOGLALTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGTANARFOGLALTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGTANARFOGLALTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUKODESIHELYADATSZOLGALTATAS                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELYADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELYADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUKODESIHELYADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELYADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYADATSZOLGALTATAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUKODESIHELYADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELYADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYADATSZOLGALTATAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_INTEZMENYESZKOZADATSZOLGALTA                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYESZKOZADATSZOLGALTA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYESZKOZADATSZOLGALTA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_INTEZMENYESZKOZADATSZOLGALTA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA
        AS
        SELECT *
        FROM dbo.T_INTEZMENYESZKOZADATSZOLGALTA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYESZKOZADATSZOLGALTA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_INTEZMENYESZKOZADATSZOLGALTA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA
        AS
        SELECT *
        FROM dbo.T_INTEZMENYESZKOZADATSZOLGALTA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYESZKOZADATSZOLGALTA_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYESZKOZADATSZOLGALTA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_VEZETOIORASZAMOKTIPUS                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_VEZETOIORASZAMOKTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VEZETOIORASZAMOKTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_VEZETOIORASZAMOKTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VEZETOIORASZAMOKTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VEZETOIORASZAMOKTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VEZETOIORASZAMOKTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_VEZETOIORASZAMOKTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VEZETOIORASZAMOKTIPUS
        AS
        SELECT *
        FROM dbo.T_VEZETOIORASZAMOKTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_VEZETOIORASZAMOKTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VEZETOIORASZAMOKTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_VEZETOIORASZAMOKTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_VEZETOIORASZAMOKTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VEZETOIORASZAMOKTIPUS
        AS
        SELECT *
        FROM dbo.T_VEZETOIORASZAMOKTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_VEZETOIORASZAMOKTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VEZETOIORASZAMOKTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_VEZETOIORASZAMOKTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FOGLALKOZTATASTIPUSA                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZTATASTIPUSA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZTATASTIPUSA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZTATASTIPUSA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZTATASTIPUSA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZTATASTIPUSA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZTATASTIPUSA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FOGLALKOZTATASTIPUSA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZTATASTIPUSA
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZTATASTIPUSA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZTATASTIPUSA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZTATASTIPUSA_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZTATASTIPUSA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FOGLALKOZTATASTIPUSA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZTATASTIPUSA
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZTATASTIPUSA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZTATASTIPUSA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZTATASTIPUSA_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZTATASTIPUSA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERETTSEGISZINT                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERETTSEGISZINT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGISZINT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERETTSEGISZINT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGISZINT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGISZINT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGISZINT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERETTSEGISZINT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGISZINT
        AS
        SELECT *
        FROM dbo.T_ERETTSEGISZINT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGISZINT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGISZINT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGISZINT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERETTSEGISZINT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGISZINT
        AS
        SELECT *
        FROM dbo.T_ERETTSEGISZINT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGISZINT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGISZINT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGISZINT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERETTSEGITIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERETTSEGITIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITIPUS
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERETTSEGITIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITIPUS
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERETTSEGIEREDMENY                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERETTSEGIEREDMENY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGIEREDMENY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERETTSEGIEREDMENY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGIEREDMENY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGIEREDMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGIEREDMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERETTSEGIEREDMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGIEREDMENY
        AS
        SELECT *
        FROM dbo.T_ERETTSEGIEREDMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGIEREDMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGIEREDMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGIEREDMENY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERETTSEGIEREDMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGIEREDMENY
        AS
        SELECT *
        FROM dbo.T_ERETTSEGIEREDMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGIEREDMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGIEREDMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGIEREDMENY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERETTSEGITANTARGYADATOK                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITANTARGYADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITANTARGYADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITANTARGYADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITANTARGYADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITANTARGYADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITANTARGYADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERETTSEGITANTARGYADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGYADATOK
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGYADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITANTARGYADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGYADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGYADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERETTSEGITANTARGYADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGYADATOK
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGYADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITANTARGYADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGYADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGYADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERETTSEGITANTARGY                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITANTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITANTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERETTSEGITANTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERETTSEGITANTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERETTSEGITANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERETTSEGITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGY
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGY
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERETTSEGITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGY
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERETTSEGITANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERETTSEGITANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERETTSEGITANTARGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TOVABBIMUNKAUGYIADATOK                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TOVABBIMUNKAUGYIADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TOVABBIMUNKAUGYIADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TOVABBIMUNKAUGYIADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK
        AS
        SELECT *
        FROM dbo.T_TOVABBIMUNKAUGYIADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TOVABBIMUNKAUGYIADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_TOVABBIMUNKAUGYIADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TOVABBIMUNKAUGYIADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK
        AS
        SELECT *
        FROM dbo.T_TOVABBIMUNKAUGYIADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TOVABBIMUNKAUGYIADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TOVABBIMUNKAUGYIADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_TOVABBIMUNKAUGYIADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_RESZSZAKKEPESITESTIPUS                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_RESZSZAKKEPESITESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RESZSZAKKEPESITESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_RESZSZAKKEPESITESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RESZSZAKKEPESITESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RESZSZAKKEPESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RESZSZAKKEPESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_RESZSZAKKEPESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZSZAKKEPESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_RESZSZAKKEPESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_RESZSZAKKEPESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZSZAKKEPESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RESZSZAKKEPESITESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_RESZSZAKKEPESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZSZAKKEPESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_RESZSZAKKEPESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_RESZSZAKKEPESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZSZAKKEPESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RESZSZAKKEPESITESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_AGAZATTIPUS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_AGAZATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_AGAZATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_AGAZATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_AGAZATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_AGAZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_AGAZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_AGAZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AGAZATTIPUS
        AS
        SELECT *
        FROM dbo.T_AGAZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_AGAZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AGAZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_AGAZATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_AGAZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AGAZATTIPUS
        AS
        SELECT *
        FROM dbo.T_AGAZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_AGAZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AGAZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_AGAZATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZAKMACSOPORTTIPUS                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZAKMACSOPORTTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZAKMACSOPORTTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZAKMACSOPORTTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZAKMACSOPORTTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZAKMACSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZAKMACSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZAKMACSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKMACSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_SZAKMACSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZAKMACSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKMACSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZAKMACSOPORTTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZAKMACSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKMACSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_SZAKMACSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZAKMACSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKMACSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZAKMACSOPORTTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZAKKEPESITESTIPUS                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZAKKEPESITESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZAKKEPESITESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZAKKEPESITESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZAKKEPESITESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZAKKEPESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZAKKEPESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZAKKEPESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKKEPESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_SZAKKEPESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZAKKEPESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKKEPESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZAKKEPESITESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZAKKEPESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKKEPESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_SZAKKEPESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZAKKEPESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZAKKEPESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZAKKEPESITESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUKODESIHELYTIPUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUKODESIHELYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYTIPUS
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUKODESIHELYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYTIPUS
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IKTESZKOZHASZNALATMOD                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IKTESZKOZHASZNALATMOD', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTESZKOZHASZNALATMOD'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IKTESZKOZHASZNALATMOD_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTESZKOZHASZNALATMOD_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTESZKOZHASZNALATMOD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTESZKOZHASZNALATMOD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IKTESZKOZHASZNALATMOD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTESZKOZHASZNALATMOD
        AS
        SELECT *
        FROM dbo.T_IKTESZKOZHASZNALATMOD
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IKTESZKOZHASZNALATMOD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTESZKOZHASZNALATMOD_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTESZKOZHASZNALATMOD
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IKTESZKOZHASZNALATMOD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTESZKOZHASZNALATMOD
        AS
        SELECT *
        FROM dbo.T_IKTESZKOZHASZNALATMOD
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IKTESZKOZHASZNALATMOD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTESZKOZHASZNALATMOD_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTESZKOZHASZNALATMOD'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ELSODLEGESIKTESZKOZ                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ELSODLEGESIKTESZKOZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELSODLEGESIKTESZKOZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ELSODLEGESIKTESZKOZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELSODLEGESIKTESZKOZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELSODLEGESIKTESZKOZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELSODLEGESIKTESZKOZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ELSODLEGESIKTESZKOZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELSODLEGESIKTESZKOZ
        AS
        SELECT *
        FROM dbo.T_ELSODLEGESIKTESZKOZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ELSODLEGESIKTESZKOZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELSODLEGESIKTESZKOZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELSODLEGESIKTESZKOZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ELSODLEGESIKTESZKOZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELSODLEGESIKTESZKOZ
        AS
        SELECT *
        FROM dbo.T_ELSODLEGESIKTESZKOZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ELSODLEGESIKTESZKOZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELSODLEGESIKTESZKOZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELSODLEGESIKTESZKOZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PEDAGOGUSIKTADATSZOLGALTATAS                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSIKTADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSIKTADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PEDAGOGUSIKTADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSIKTADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSIKTADATSZOLGALTATAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PEDAGOGUSIKTADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSIKTADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSIKTADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSIKTADATSZOLGALTATAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_WIFIELERES                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_WIFIELERES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_WIFIELERES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_WIFIELERES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_WIFIELERES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_WIFIELERES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_WIFIELERES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_WIFIELERES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_WIFIELERES
        AS
        SELECT *
        FROM dbo.T_WIFIELERES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_WIFIELERES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_WIFIELERES_OSSZES
        AS
        SELECT *
        FROM dbo.T_WIFIELERES
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_WIFIELERES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_WIFIELERES
        AS
        SELECT *
        FROM dbo.T_WIFIELERES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_WIFIELERES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_WIFIELERES_OSSZES
        AS
        SELECT *
        FROM dbo.T_WIFIELERES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IKTKOMPETENCIASZINT                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IKTKOMPETENCIASZINT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTKOMPETENCIASZINT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IKTKOMPETENCIASZINT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTKOMPETENCIASZINT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTKOMPETENCIASZINT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTKOMPETENCIASZINT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IKTKOMPETENCIASZINT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTKOMPETENCIASZINT
        AS
        SELECT *
        FROM dbo.T_IKTKOMPETENCIASZINT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IKTKOMPETENCIASZINT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTKOMPETENCIASZINT_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTKOMPETENCIASZINT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IKTKOMPETENCIASZINT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTKOMPETENCIASZINT
        AS
        SELECT *
        FROM dbo.T_IKTKOMPETENCIASZINT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IKTKOMPETENCIASZINT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTKOMPETENCIASZINT_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTKOMPETENCIASZINT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENAPLOHASZNALAT                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENAPLOHASZNALAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOHASZNALAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENAPLOHASZNALAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOHASZNALAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOHASZNALAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOHASZNALAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENAPLOHASZNALAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOHASZNALAT
        AS
        SELECT *
        FROM dbo.T_ENAPLOHASZNALAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOHASZNALAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOHASZNALAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOHASZNALAT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENAPLOHASZNALAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOHASZNALAT
        AS
        SELECT *
        FROM dbo.T_ENAPLOHASZNALAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOHASZNALAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOHASZNALAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOHASZNALAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TAGOZATTIPUS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TAGOZATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TAGOZATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TAGOZATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TAGOZATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TAGOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TAGOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TAGOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TAGOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_TAGOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TAGOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TAGOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TAGOZATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TAGOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TAGOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_TAGOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TAGOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TAGOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TAGOZATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NEBULO                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NEBULO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEBULO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NEBULO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEBULO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEBULO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEBULO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NEBULO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEBULO
        AS
        SELECT *
        FROM dbo.T_NEBULO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NEBULO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEBULO_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEBULO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NEBULO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEBULO
        AS
        SELECT *
        FROM dbo.T_NEBULO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NEBULO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEBULO_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEBULO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELVETELSTATUSZATIPUS                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELVETELSTATUSZATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELVETELSTATUSZATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELVETELSTATUSZATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELVETELSTATUSZATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELVETELSTATUSZATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELVETELSTATUSZATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELVETELSTATUSZATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELVETELSTATUSZATIPUS
        AS
        SELECT *
        FROM dbo.T_FELVETELSTATUSZATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELVETELSTATUSZATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELVETELSTATUSZATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELVETELSTATUSZATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELVETELSTATUSZATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELVETELSTATUSZATIPUS
        AS
        SELECT *
        FROM dbo.T_FELVETELSTATUSZATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELVETELSTATUSZATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELVETELSTATUSZATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELVETELSTATUSZATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_UPLOADEDFILE                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_UPLOADEDFILE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_UPLOADEDFILE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_UPLOADEDFILE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_UPLOADEDFILE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_UPLOADEDFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_UPLOADEDFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_UPLOADEDFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_UPLOADEDFILE
        AS
        SELECT *
        FROM dbo.T_UPLOADEDFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_UPLOADEDFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_UPLOADEDFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_UPLOADEDFILE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_UPLOADEDFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_UPLOADEDFILE
        AS
        SELECT *
        FROM dbo.T_UPLOADEDFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_UPLOADEDFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_UPLOADEDFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_UPLOADEDFILE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IDOKERET                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IDOKERET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IDOKERET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IDOKERET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IDOKERET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IDOKERET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IDOKERET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IDOKERET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IDOKERET
        AS
        SELECT *
        FROM dbo.T_IDOKERET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IDOKERET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IDOKERET_OSSZES
        AS
        SELECT *
        FROM dbo.T_IDOKERET
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IDOKERET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IDOKERET
        AS
        SELECT *
        FROM dbo.T_IDOKERET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IDOKERET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IDOKERET_OSSZES
        AS
        SELECT *
        FROM dbo.T_IDOKERET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EPENZTARCABIZONYLAT                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EPENZTARCABIZONYLAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCABIZONYLAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EPENZTARCABIZONYLAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCABIZONYLAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCABIZONYLAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCABIZONYLAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EPENZTARCABIZONYLAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCABIZONYLAT
        AS
        SELECT *
        FROM dbo.T_EPENZTARCABIZONYLAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCABIZONYLAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCABIZONYLAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCABIZONYLAT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EPENZTARCABIZONYLAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCABIZONYLAT
        AS
        SELECT *
        FROM dbo.T_EPENZTARCABIZONYLAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCABIZONYLAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCABIZONYLAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCABIZONYLAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSSZEGTULLEPESTIPUS                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSSZEGTULLEPESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSSZEGTULLEPESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSSZEGTULLEPESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSSZEGTULLEPESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSSZEGTULLEPESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSSZEGTULLEPESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSSZEGTULLEPESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSSZEGTULLEPESTIPUS
        AS
        SELECT *
        FROM dbo.T_OSSZEGTULLEPESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSSZEGTULLEPESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSSZEGTULLEPESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSSZEGTULLEPESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSSZEGTULLEPESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSSZEGTULLEPESTIPUS
        AS
        SELECT *
        FROM dbo.T_OSSZEGTULLEPESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSSZEGTULLEPESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSSZEGTULLEPESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSSZEGTULLEPESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EPENZTARCATETEL                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EPENZTARCATETEL', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCATETEL'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EPENZTARCATETEL_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCATETEL_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCATETEL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCATETEL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EPENZTARCATETEL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETEL
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETEL
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCATETEL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETEL_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETEL
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EPENZTARCATETEL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETEL
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETEL
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCATETEL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETEL_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETEL'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EPENZTARCATETELSTATUSZ                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EPENZTARCATETELSTATUSZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCATETELSTATUSZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EPENZTARCATETELSTATUSZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCATETELSTATUSZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCATETELSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCATETELSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EPENZTARCATETELSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETELSTATUSZ
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETELSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCATETELSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETELSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETELSTATUSZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EPENZTARCATETELSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETELSTATUSZ
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETELSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCATETELSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCATETELSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCATETELSTATUSZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EPENZTARCAPARAMETEREK                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EPENZTARCAPARAMETEREK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCAPARAMETEREK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EPENZTARCAPARAMETEREK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EPENZTARCAPARAMETEREK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCAPARAMETEREK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EPENZTARCAPARAMETEREK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EPENZTARCAPARAMETEREK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCAPARAMETEREK
        AS
        SELECT *
        FROM dbo.T_EPENZTARCAPARAMETEREK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCAPARAMETEREK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCAPARAMETEREK_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCAPARAMETEREK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EPENZTARCAPARAMETEREK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCAPARAMETEREK
        AS
        SELECT *
        FROM dbo.T_EPENZTARCAPARAMETEREK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EPENZTARCAPARAMETEREK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EPENZTARCAPARAMETEREK_OSSZES
        AS
        SELECT *
        FROM dbo.T_EPENZTARCAPARAMETEREK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HIBAJEGY                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HIBAJEGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HIBAJEGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HIBAJEGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HIBAJEGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HIBAJEGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HIBAJEGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HIBAJEGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGY
        AS
        SELECT *
        FROM dbo.T_HIBAJEGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HIBAJEGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_HIBAJEGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HIBAJEGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGY
        AS
        SELECT *
        FROM dbo.T_HIBAJEGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HIBAJEGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_HIBAJEGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HIBAJEGYSTATUSZ                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HIBAJEGYSTATUSZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HIBAJEGYSTATUSZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HIBAJEGYSTATUSZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HIBAJEGYSTATUSZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HIBAJEGYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HIBAJEGYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HIBAJEGYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_HIBAJEGYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HIBAJEGYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_HIBAJEGYSTATUSZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HIBAJEGYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_HIBAJEGYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HIBAJEGYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HIBAJEGYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_HIBAJEGYSTATUSZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PRIORITAS                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PRIORITAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PRIORITAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PRIORITAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PRIORITAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PRIORITAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PRIORITAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PRIORITAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PRIORITAS
        AS
        SELECT *
        FROM dbo.T_PRIORITAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PRIORITAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PRIORITAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PRIORITAS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PRIORITAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PRIORITAS
        AS
        SELECT *
        FROM dbo.T_PRIORITAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PRIORITAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PRIORITAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PRIORITAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FORRAS                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FORRAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORRAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FORRAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORRAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORRAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORRAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FORRAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORRAS
        AS
        SELECT *
        FROM dbo.T_FORRAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FORRAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORRAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORRAS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FORRAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORRAS
        AS
        SELECT *
        FROM dbo.T_FORRAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FORRAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORRAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORRAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZERZODOSZEMELYPOZICIO                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZERZODOSZEMELYPOZICIO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZERZODOSZEMELYPOZICIO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZERZODOSZEMELYPOZICIO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZERZODOSZEMELYPOZICIO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZERZODOSZEMELYPOZICIO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZERZODOSZEMELYPOZICIO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZERZODOSZEMELYPOZICIO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZERZODOSZEMELYPOZICIO
        AS
        SELECT *
        FROM dbo.T_SZERZODOSZEMELYPOZICIO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZERZODOSZEMELYPOZICIO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZERZODOSZEMELYPOZICIO_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZERZODOSZEMELYPOZICIO
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZERZODOSZEMELYPOZICIO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZERZODOSZEMELYPOZICIO
        AS
        SELECT *
        FROM dbo.T_SZERZODOSZEMELYPOZICIO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZERZODOSZEMELYPOZICIO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZERZODOSZEMELYPOZICIO_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZERZODOSZEMELYPOZICIO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENAPLOTIPUS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENAPLOTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENAPLOTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENAPLOTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOTIPUS
        AS
        SELECT *
        FROM dbo.T_ENAPLOTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENAPLOTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOTIPUS
        AS
        SELECT *
        FROM dbo.T_ENAPLOTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENAPLOFORRAS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENAPLOFORRAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOFORRAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENAPLOFORRAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOFORRAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOFORRAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOFORRAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENAPLOFORRAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOFORRAS
        AS
        SELECT *
        FROM dbo.T_ENAPLOFORRAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOFORRAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOFORRAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOFORRAS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENAPLOFORRAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOFORRAS
        AS
        SELECT *
        FROM dbo.T_ENAPLOFORRAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOFORRAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOFORRAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOFORRAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ADATSZOLGALTATASENAPLO                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ADATSZOLGALTATASENAPLO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ADATSZOLGALTATASENAPLO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ADATSZOLGALTATASENAPLO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ADATSZOLGALTATASENAPLO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ADATSZOLGALTATASENAPLO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ADATSZOLGALTATASENAPLO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ADATSZOLGALTATASENAPLO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ADATSZOLGALTATASENAPLO
        AS
        SELECT *
        FROM dbo.T_ADATSZOLGALTATASENAPLO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ADATSZOLGALTATASENAPLO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ADATSZOLGALTATASENAPLO_OSSZES
        AS
        SELECT *
        FROM dbo.T_ADATSZOLGALTATASENAPLO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ADATSZOLGALTATASENAPLO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ADATSZOLGALTATASENAPLO
        AS
        SELECT *
        FROM dbo.T_ADATSZOLGALTATASENAPLO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ADATSZOLGALTATASENAPLO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ADATSZOLGALTATASENAPLO_OSSZES
        AS
        SELECT *
        FROM dbo.T_ADATSZOLGALTATASENAPLO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENAPLOINFRA                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENAPLOINFRA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOINFRA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENAPLOINFRA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENAPLOINFRA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOINFRA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENAPLOINFRA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENAPLOINFRA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOINFRA
        AS
        SELECT *
        FROM dbo.T_ENAPLOINFRA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOINFRA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOINFRA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOINFRA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENAPLOINFRA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOINFRA
        AS
        SELECT *
        FROM dbo.T_ENAPLOINFRA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENAPLOINFRA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENAPLOINFRA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENAPLOINFRA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NEMKOTOTTMUNKAIDO                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NEMKOTOTTMUNKAIDO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEMKOTOTTMUNKAIDO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NEMKOTOTTMUNKAIDO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEMKOTOTTMUNKAIDO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEMKOTOTTMUNKAIDO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEMKOTOTTMUNKAIDO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NEMKOTOTTMUNKAIDO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEMKOTOTTMUNKAIDO
        AS
        SELECT *
        FROM dbo.T_NEMKOTOTTMUNKAIDO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NEMKOTOTTMUNKAIDO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEMKOTOTTMUNKAIDO_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEMKOTOTTMUNKAIDO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NEMKOTOTTMUNKAIDO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEMKOTOTTMUNKAIDO
        AS
        SELECT *
        FROM dbo.T_NEMKOTOTTMUNKAIDO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NEMKOTOTTMUNKAIDO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEMKOTOTTMUNKAIDO_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEMKOTOTTMUNKAIDO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESLADAT                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESLADAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESLADAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESLADAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESLADAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESLADAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESLADAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESLADAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADAT
        AS
        SELECT *
        FROM dbo.T_ESLADAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESLADAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESLADAT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESLADAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADAT
        AS
        SELECT *
        FROM dbo.T_ESLADAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESLADAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESLADAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOESLADATOK                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOESLADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOESLADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOESLADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOESLADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOESLADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOESLADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOESLADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESLADATOK
        AS
        SELECT *
        FROM dbo.T_TANULOESLADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOESLADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESLADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOESLADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOESLADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESLADATOK
        AS
        SELECT *
        FROM dbo.T_TANULOESLADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOESLADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESLADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOESLADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESLADATTIPUS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESLADATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESLADATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESLADATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESLADATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESLADATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESLADATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESLADATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADATTIPUS
        AS
        SELECT *
        FROM dbo.T_ESLADATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESLADATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESLADATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESLADATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADATTIPUS
        AS
        SELECT *
        FROM dbo.T_ESLADATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESLADATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESLADATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESLADATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FOGLALKOZASARCHIV                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZASARCHIV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZASARCHIV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZASARCHIV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZASARCHIV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZASARCHIV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZASARCHIV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FOGLALKOZASARCHIV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASARCHIV
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASARCHIV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZASARCHIV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASARCHIV_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASARCHIV
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FOGLALKOZASARCHIV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASARCHIV
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASARCHIV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZASARCHIV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASARCHIV_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASARCHIV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SOROLASOKATIPUS                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SOROLASOKATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SOROLASOKATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SOROLASOKATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SOROLASOKATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SOROLASOKATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SOROLASOKATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SOROLASOKATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SOROLASOKATIPUS
        AS
        SELECT *
        FROM dbo.T_SOROLASOKATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SOROLASOKATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SOROLASOKATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SOROLASOKATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SOROLASOKATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SOROLASOKATIPUS
        AS
        SELECT *
        FROM dbo.T_SOROLASOKATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SOROLASOKATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SOROLASOKATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SOROLASOKATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CSOPORTTIPUS_FOGLALKOZASTIPU                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORTTIPUS_FOGLALKOZASTIPU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORTTIPUS_FOGLALKOZASTIPU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CSOPORTTIPUS_FOGLALKOZASTIPU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS_FOGLALKOZASTIPU
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS_FOGLALKOZASTIPU
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSOPORTTIPUS_FOGLALKOZASTIPU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS_FOGLALKOZASTIPU
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_FOGLALKOZASTIPU_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS_FOGLALKOZASTIPU'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KIRTELEPHELY                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KIRTELEPHELY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIRTELEPHELY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KIRTELEPHELY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIRTELEPHELY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIRTELEPHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIRTELEPHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KIRTELEPHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIRTELEPHELY
        AS
        SELECT *
        FROM dbo.T_KIRTELEPHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KIRTELEPHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIRTELEPHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIRTELEPHELY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KIRTELEPHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIRTELEPHELY
        AS
        SELECT *
        FROM dbo.T_KIRTELEPHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KIRTELEPHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIRTELEPHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIRTELEPHELY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUNKAIDOKEDVEZMENYOKA                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAIDOKEDVEZMENYOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAIDOKEDVEZMENYOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUNKAIDOKEDVEZMENYOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA
        AS
        SELECT *
        FROM dbo.T_MUNKAIDOKEDVEZMENYOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUNKAIDOKEDVEZMENYOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAIDOKEDVEZMENYOKA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUNKAIDOKEDVEZMENYOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA
        AS
        SELECT *
        FROM dbo.T_MUNKAIDOKEDVEZMENYOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUNKAIDOKEDVEZMENYOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAIDOKEDVEZMENYOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAIDOKEDVEZMENYOKA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_BESOROLASIFOKOZATTIPUS                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_BESOROLASIFOKOZATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BESOROLASIFOKOZATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_BESOROLASIFOKOZATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BESOROLASIFOKOZATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BESOROLASIFOKOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BESOROLASIFOKOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_BESOROLASIFOKOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BESOROLASIFOKOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_BESOROLASIFOKOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_BESOROLASIFOKOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BESOROLASIFOKOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_BESOROLASIFOKOZATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_BESOROLASIFOKOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BESOROLASIFOKOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_BESOROLASIFOKOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_BESOROLASIFOKOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BESOROLASIFOKOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_BESOROLASIFOKOZATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_INTEZMENYADATSZOLGALTATAS                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYADATSZOLGALTATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_INTEZMENYADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATSZOLGALTATAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_INTEZMENYADATSZOLGALTATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATSZOLGALTATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYADATSZOLGALTATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATSZOLGALTATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATSZOLGALTATAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PEDAGOGUSSTATUSZ                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSSTATUSZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSSTATUSZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSSTATUSZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSSTATUSZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PEDAGOGUSSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSSTATUSZ
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSSTATUSZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PEDAGOGUSSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSSTATUSZ
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSSTATUSZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KRETATIPUS                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KRETATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KRETATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KRETATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KRETATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KRETATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KRETATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KRETATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KRETATIPUS
        AS
        SELECT *
        FROM dbo.T_KRETATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KRETATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KRETATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KRETATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KRETATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KRETATIPUS
        AS
        SELECT *
        FROM dbo.T_KRETATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KRETATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KRETATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KRETATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANTARGYNEVHEZKATEGORIA                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTARGYNEVHEZKATEGORIA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTARGYNEVHEZKATEGORIA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANTARGYNEVHEZKATEGORIA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA
        AS
        SELECT *
        FROM dbo.T_TANTARGYNEVHEZKATEGORIA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANTARGYNEVHEZKATEGORIA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTARGYNEVHEZKATEGORIA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANTARGYNEVHEZKATEGORIA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA
        AS
        SELECT *
        FROM dbo.T_TANTARGYNEVHEZKATEGORIA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANTARGYNEVHEZKATEGORIA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGYNEVHEZKATEGORIA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTARGYNEVHEZKATEGORIA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NAPTARIHET                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NAPTARIHET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARIHET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NAPTARIHET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARIHET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTARIHET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTARIHET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NAPTARIHET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARIHET
        AS
        SELECT *
        FROM dbo.T_NAPTARIHET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NAPTARIHET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARIHET_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTARIHET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NAPTARIHET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARIHET
        AS
        SELECT *
        FROM dbo.T_NAPTARIHET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NAPTARIHET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARIHET_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTARIHET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HELYETTESITESIIDOSZAK                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HELYETTESITESIIDOSZAK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HELYETTESITESIIDOSZAK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HELYETTESITESIIDOSZAK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HELYETTESITESIIDOSZAK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HELYETTESITESIIDOSZAK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HELYETTESITESIIDOSZAK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HELYETTESITESIIDOSZAK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESIIDOSZAK
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESIIDOSZAK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HELYETTESITESIIDOSZAK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESIIDOSZAK_OSSZES
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESIIDOSZAK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HELYETTESITESIIDOSZAK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESIIDOSZAK
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESIIDOSZAK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HELYETTESITESIIDOSZAK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESIIDOSZAK_OSSZES
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESIIDOSZAK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TELEPULES                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TELEPULES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEPULES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TELEPULES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEPULES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEPULES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEPULES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TELEPULES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEPULES
        AS
        SELECT *
        FROM dbo.T_TELEPULES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TELEPULES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEPULES_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEPULES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TELEPULES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEPULES
        AS
        SELECT *
        FROM dbo.T_TELEPULES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TELEPULES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEPULES_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEPULES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_INTEZMENY                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_INTEZMENY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_INTEZMENY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_INTEZMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENY
        AS
        SELECT *
        FROM dbo.T_INTEZMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_INTEZMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENY
        AS
        SELECT *
        FROM dbo.T_INTEZMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IKTATOTTDOKUMENTUMOK                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IKTATOTTDOKUMENTUMOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTATOTTDOKUMENTUMOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IKTATOTTDOKUMENTUMOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IKTATOTTDOKUMENTUMOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTATOTTDOKUMENTUMOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IKTATOTTDOKUMENTUMOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IKTATOTTDOKUMENTUMOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTATOTTDOKUMENTUMOK
        AS
        SELECT *
        FROM dbo.T_IKTATOTTDOKUMENTUMOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IKTATOTTDOKUMENTUMOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTATOTTDOKUMENTUMOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTATOTTDOKUMENTUMOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IKTATOTTDOKUMENTUMOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTATOTTDOKUMENTUMOK
        AS
        SELECT *
        FROM dbo.T_IKTATOTTDOKUMENTUMOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IKTATOTTDOKUMENTUMOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IKTATOTTDOKUMENTUMOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_IKTATOTTDOKUMENTUMOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_JOGOSULTSAG                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_JOGOSULTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_JOGOSULTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_JOGOSULTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_JOGOSULTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_JOGOSULTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_JOGOSULTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_JOGOSULTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_JOGOSULTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZEREPKORTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZEREPKORTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZEREPKORTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZEREPKORTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZEREPKORTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZEREPKORTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZEREPKORTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZEREPKORTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKORTIPUS
        AS
        SELECT *
        FROM dbo.T_SZEREPKORTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZEREPKORTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKORTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZEREPKORTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZEREPKORTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKORTIPUS
        AS
        SELECT *
        FROM dbo.T_SZEREPKORTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZEREPKORTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKORTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZEREPKORTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOKOZOSSEGISZOLGALAT                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOKOZOSSEGISZOLGALAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOKOZOSSEGISZOLGALAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOKOZOSSEGISZOLGALAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT
        AS
        SELECT *
        FROM dbo.T_TANULOKOZOSSEGISZOLGALAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOKOZOSSEGISZOLGALAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOKOZOSSEGISZOLGALAT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOKOZOSSEGISZOLGALAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT
        AS
        SELECT *
        FROM dbo.T_TANULOKOZOSSEGISZOLGALAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOKOZOSSEGISZOLGALAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOKOZOSSEGISZOLGALAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOKOZOSSEGISZOLGALAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PARTFILLSTATUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PARTFILLSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PARTFILLSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PARTFILLSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PARTFILLSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PARTFILLSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PARTFILLSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PARTFILLSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTFILLSTATUS
        AS
        SELECT *
        FROM dbo.T_PARTFILLSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PARTFILLSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTFILLSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PARTFILLSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PARTFILLSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTFILLSTATUS
        AS
        SELECT *
        FROM dbo.T_PARTFILLSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PARTFILLSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTFILLSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_PARTFILLSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_RENDSZERERTESITESEK                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_RENDSZERERTESITESEK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERERTESITESEK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_RENDSZERERTESITESEK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERERTESITESEK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERERTESITESEK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERERTESITESEK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_RENDSZERERTESITESEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERERTESITESEK
        AS
        SELECT *
        FROM dbo.T_RENDSZERERTESITESEK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERERTESITESEK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERERTESITESEK_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERERTESITESEK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_RENDSZERERTESITESEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERERTESITESEK
        AS
        SELECT *
        FROM dbo.T_RENDSZERERTESITESEK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERERTESITESEK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERERTESITESEK_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERERTESITESEK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUNKAUGYIADATOK                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUNKAUGYIADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAUGYIADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUNKAUGYIADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAUGYIADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAUGYIADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAUGYIADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUNKAUGYIADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAUGYIADATOK
        AS
        SELECT *
        FROM dbo.T_MUNKAUGYIADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUNKAUGYIADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAUGYIADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAUGYIADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUNKAUGYIADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAUGYIADATOK
        AS
        SELECT *
        FROM dbo.T_MUNKAUGYIADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUNKAUGYIADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAUGYIADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAUGYIADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SYSTEMSETTINGSCONTROLTYPE                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMSETTINGSCONTROLTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMSETTINGSCONTROLTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SYSTEMSETTINGSCONTROLTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE
        AS
        SELECT *
        FROM dbo.T_SYSTEMSETTINGSCONTROLTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMSETTINGSCONTROLTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMSETTINGSCONTROLTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SYSTEMSETTINGSCONTROLTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE
        AS
        SELECT *
        FROM dbo.T_SYSTEMSETTINGSCONTROLTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMSETTINGSCONTROLTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMSETTINGSCONTROLTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMSETTINGSCONTROLTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCHEDULERLOG                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCHEDULERLOG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERLOG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCHEDULERLOG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERLOG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERLOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERLOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCHEDULERLOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERLOG
        AS
        SELECT *
        FROM dbo.T_SCHEDULERLOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERLOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERLOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERLOG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCHEDULERLOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERLOG
        AS
        SELECT *
        FROM dbo.T_SCHEDULERLOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERLOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERLOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERLOG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MULASZTASSTATISZTIKATIPUS                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MULASZTASSTATISZTIKATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MULASZTASSTATISZTIKATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MULASZTASSTATISZTIKATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS
        AS
        SELECT *
        FROM dbo.T_MULASZTASSTATISZTIKATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MULASZTASSTATISZTIKATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MULASZTASSTATISZTIKATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MULASZTASSTATISZTIKATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS
        AS
        SELECT *
        FROM dbo.T_MULASZTASSTATISZTIKATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MULASZTASSTATISZTIKATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASSTATISZTIKATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MULASZTASSTATISZTIKATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOTARGYMULASZTASSTATISZT                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOTARGYMULASZTASSTATISZT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOTARGYMULASZTASSTATISZT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOTARGYMULASZTASSTATISZT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT
        AS
        SELECT *
        FROM dbo.T_TANULOTARGYMULASZTASSTATISZT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOTARGYMULASZTASSTATISZT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOTARGYMULASZTASSTATISZT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOTARGYMULASZTASSTATISZT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT
        AS
        SELECT *
        FROM dbo.T_TANULOTARGYMULASZTASSTATISZT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOTARGYMULASZTASSTATISZT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOTARGYMULASZTASSTATISZT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOTARGYMULASZTASSTATISZT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOMULASZTASSTATISZTIKA                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMULASZTASSTATISZTIKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMULASZTASSTATISZTIKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOMULASZTASSTATISZTIKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTASSTATISZTIKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOMULASZTASSTATISZTIKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTASSTATISZTIKA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOMULASZTASSTATISZTIKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTASSTATISZTIKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOMULASZTASSTATISZTIKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTASSTATISZTIKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTASSTATISZTIKA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OLDALLATOGATOTTSAG                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OLDALLATOGATOTTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OLDALLATOGATOTTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OLDALLATOGATOTTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OLDALLATOGATOTTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OLDALLATOGATOTTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OLDALLATOGATOTTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OLDALLATOGATOTTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OLDALLATOGATOTTSAG
        AS
        SELECT *
        FROM dbo.T_OLDALLATOGATOTTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OLDALLATOGATOTTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OLDALLATOGATOTTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OLDALLATOGATOTTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OLDALLATOGATOTTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OLDALLATOGATOTTSAG
        AS
        SELECT *
        FROM dbo.T_OLDALLATOGATOTTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OLDALLATOGATOTTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OLDALLATOGATOTTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_OLDALLATOGATOTTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELADATELLATASIHELY                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELADATELLATASIHELY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELADATELLATASIHELY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELADATELLATASIHELY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELADATELLATASIHELY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELADATELLATASIHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELADATELLATASIHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELADATELLATASIHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELADATELLATASIHELY
        AS
        SELECT *
        FROM dbo.T_FELADATELLATASIHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELADATELLATASIHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELADATELLATASIHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELADATELLATASIHELY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELADATELLATASIHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELADATELLATASIHELY
        AS
        SELECT *
        FROM dbo.T_FELADATELLATASIHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELADATELLATASIHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELADATELLATASIHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELADATELLATASIHELY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KIZAROCSOPORT                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KIZAROCSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIZAROCSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KIZAROCSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIZAROCSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIZAROCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIZAROCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KIZAROCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORT
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KIZAROCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KIZAROCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORT
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KIZAROCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_RENDSZERBEALLITASTIPUS                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_RENDSZERBEALLITASTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERBEALLITASTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_RENDSZERBEALLITASTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERBEALLITASTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERBEALLITASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERBEALLITASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_RENDSZERBEALLITASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITASTIPUS
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERBEALLITASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITASTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_RENDSZERBEALLITASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITASTIPUS
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERBEALLITASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITASTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ORATERVTARGY                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ORATERVTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORATERVTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORATERVTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORATERVTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORATERVTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORATERVTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ORATERVTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERVTARGY
        AS
        SELECT *
        FROM dbo.T_ORATERVTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORATERVTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERVTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORATERVTARGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORATERVTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERVTARGY
        AS
        SELECT *
        FROM dbo.T_ORATERVTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ORATERVTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERVTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORATERVTARGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_RENDSZERBEALLITAS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_RENDSZERBEALLITAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERBEALLITAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_RENDSZERBEALLITAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RENDSZERBEALLITAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERBEALLITAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_RENDSZERBEALLITAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_RENDSZERBEALLITAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITAS
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERBEALLITAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_RENDSZERBEALLITAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITAS
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_RENDSZERBEALLITAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RENDSZERBEALLITAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_RENDSZERBEALLITAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ORATERV                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ORATERV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORATERV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORATERV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORATERV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORATERV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORATERV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ORATERV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERV
        AS
        SELECT *
        FROM dbo.T_ORATERV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORATERV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERV_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORATERV
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORATERV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERV
        AS
        SELECT *
        FROM dbo.T_ORATERV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ORATERV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORATERV_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORATERV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KIZAROCSOPORTTIPUS                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KIZAROCSOPORTTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIZAROCSOPORTTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KIZAROCSOPORTTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KIZAROCSOPORTTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIZAROCSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KIZAROCSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KIZAROCSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KIZAROCSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORTTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KIZAROCSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KIZAROCSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KIZAROCSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KIZAROCSOPORTTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELHASZNALOERTESITESBEALLITA                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOERTESITESBEALLITA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOERTESITESBEALLITA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELHASZNALOERTESITESBEALLITA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITESBEALLITA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOERTESITESBEALLITA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITESBEALLITA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALOERTESITESBEALLITA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITESBEALLITA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOERTESITESBEALLITA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITESBEALLITA_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITESBEALLITA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANARIATLAGSULY                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANARIATLAGSULY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANARIATLAGSULY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANARIATLAGSULY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANARIATLAGSULY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANARIATLAGSULY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANARIATLAGSULY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANARIATLAGSULY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARIATLAGSULY
        AS
        SELECT *
        FROM dbo.T_TANARIATLAGSULY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANARIATLAGSULY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARIATLAGSULY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANARIATLAGSULY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANARIATLAGSULY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARIATLAGSULY
        AS
        SELECT *
        FROM dbo.T_TANARIATLAGSULY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANARIATLAGSULY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARIATLAGSULY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANARIATLAGSULY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANARITANTARGY                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANARITANTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANARITANTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANARITANTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANARITANTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANARITANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANARITANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANARITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARITANTARGY
        AS
        SELECT *
        FROM dbo.T_TANARITANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANARITANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARITANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANARITANTARGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANARITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARITANTARGY
        AS
        SELECT *
        FROM dbo.T_TANARITANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANARITANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANARITANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANARITANTARGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTESITESGENERALASTORTENET                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTESITESGENERALASTORTENET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESGENERALASTORTENET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTESITESGENERALASTORTENET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESGENERALASTORTENET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESGENERALASTORTENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESGENERALASTORTENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTESITESGENERALASTORTENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESGENERALASTORTENET
        AS
        SELECT *
        FROM dbo.T_ERTESITESGENERALASTORTENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESGENERALASTORTENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESGENERALASTORTENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESGENERALASTORTENET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTESITESGENERALASTORTENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESGENERALASTORTENET
        AS
        SELECT *
        FROM dbo.T_ERTESITESGENERALASTORTENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESGENERALASTORTENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESGENERALASTORTENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESGENERALASTORTENET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MESSAGESTATUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MESSAGESTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MESSAGESTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MESSAGESTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MESSAGESTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MESSAGESTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MESSAGESTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MESSAGESTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGESTATUS
        AS
        SELECT *
        FROM dbo.T_MESSAGESTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MESSAGESTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGESTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MESSAGESTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MESSAGESTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGESTATUS
        AS
        SELECT *
        FROM dbo.T_MESSAGESTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MESSAGESTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGESTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MESSAGESTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_GLOBALISBEALLITASOK                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_GLOBALISBEALLITASOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GLOBALISBEALLITASOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_GLOBALISBEALLITASOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GLOBALISBEALLITASOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GLOBALISBEALLITASOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GLOBALISBEALLITASOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_GLOBALISBEALLITASOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALISBEALLITASOK
        AS
        SELECT *
        FROM dbo.T_GLOBALISBEALLITASOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_GLOBALISBEALLITASOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALISBEALLITASOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_GLOBALISBEALLITASOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_GLOBALISBEALLITASOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALISBEALLITASOK
        AS
        SELECT *
        FROM dbo.T_GLOBALISBEALLITASOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_GLOBALISBEALLITASOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALISBEALLITASOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_GLOBALISBEALLITASOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_JOGYAKORLAT                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_JOGYAKORLAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGYAKORLAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_JOGYAKORLAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGYAKORLAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_JOGYAKORLAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_JOGYAKORLAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_JOGYAKORLAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGYAKORLAT
        AS
        SELECT *
        FROM dbo.T_JOGYAKORLAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_JOGYAKORLAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGYAKORLAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGYAKORLAT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_JOGYAKORLAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGYAKORLAT
        AS
        SELECT *
        FROM dbo.T_JOGYAKORLAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_JOGYAKORLAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGYAKORLAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGYAKORLAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EVENTTYPE                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EVENTTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVENTTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EVENTTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVENTTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EVENTTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EVENTTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EVENTTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVENTTYPE
        AS
        SELECT *
        FROM dbo.T_EVENTTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EVENTTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVENTTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_EVENTTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EVENTTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVENTTYPE
        AS
        SELECT *
        FROM dbo.T_EVENTTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EVENTTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVENTTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_EVENTTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_GLOBALLOCK                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_GLOBALLOCK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GLOBALLOCK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_GLOBALLOCK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GLOBALLOCK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GLOBALLOCK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GLOBALLOCK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_GLOBALLOCK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALLOCK
        AS
        SELECT *
        FROM dbo.T_GLOBALLOCK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_GLOBALLOCK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALLOCK_OSSZES
        AS
        SELECT *
        FROM dbo.T_GLOBALLOCK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_GLOBALLOCK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALLOCK
        AS
        SELECT *
        FROM dbo.T_GLOBALLOCK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_GLOBALLOCK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GLOBALLOCK_OSSZES
        AS
        SELECT *
        FROM dbo.T_GLOBALLOCK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCHEDULERTRIGGERS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCHEDULERTRIGGERS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERTRIGGERS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCHEDULERTRIGGERS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERTRIGGERS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERTRIGGERS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERTRIGGERS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCHEDULERTRIGGERS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERTRIGGERS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERTRIGGERS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERTRIGGERS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERTRIGGERS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERTRIGGERS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCHEDULERTRIGGERS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERTRIGGERS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERTRIGGERS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERTRIGGERS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERTRIGGERS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERTRIGGERS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCHEDULERCONTEXTS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCHEDULERCONTEXTS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERCONTEXTS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCHEDULERCONTEXTS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERCONTEXTS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERCONTEXTS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERCONTEXTS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCHEDULERCONTEXTS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERCONTEXTS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERCONTEXTS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERCONTEXTS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERCONTEXTS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERCONTEXTS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCHEDULERCONTEXTS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERCONTEXTS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERCONTEXTS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERCONTEXTS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERCONTEXTS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERCONTEXTS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCHEDULERJOBS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCHEDULERJOBS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERJOBS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCHEDULERJOBS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCHEDULERJOBS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERJOBS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCHEDULERJOBS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCHEDULERJOBS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERJOBS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERJOBS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERJOBS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERJOBS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERJOBS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCHEDULERJOBS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERJOBS
        AS
        SELECT *
        FROM dbo.T_SCHEDULERJOBS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCHEDULERJOBS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCHEDULERJOBS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCHEDULERJOBS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTESITES                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTESITES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTESITES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITES
        AS
        SELECT *
        FROM dbo.T_ERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITES
        AS
        SELECT *
        FROM dbo.T_ERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_GONDVISELOERTESITES                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_GONDVISELOERTESITES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GONDVISELOERTESITES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_GONDVISELOERTESITES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GONDVISELOERTESITES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GONDVISELOERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GONDVISELOERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_GONDVISELOERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELOERTESITES
        AS
        SELECT *
        FROM dbo.T_GONDVISELOERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_GONDVISELOERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELOERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_GONDVISELOERTESITES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_GONDVISELOERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELOERTESITES
        AS
        SELECT *
        FROM dbo.T_GONDVISELOERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_GONDVISELOERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELOERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_GONDVISELOERTESITES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTESITESTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTESITESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTESITESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELHASZNALOERTESITES                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOERTESITES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOERTESITES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOERTESITES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOERTESITES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOERTESITES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELHASZNALOERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALOERTESITES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOERTESITES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOERTESITES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOERTESITES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTESITESSZINTIPUS                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTESITESSZINTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESSZINTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTESITESSZINTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTESITESSZINTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESSZINTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTESITESSZINTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTESITESSZINTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESSZINTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTESITESSZINTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESSZINTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESSZINTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESSZINTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTESITESSZINTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESSZINTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTESITESSZINTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTESITESSZINTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTESITESSZINTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTESITESSZINTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TEVEKENYSEG                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TEVEKENYSEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEVEKENYSEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEVEKENYSEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEVEKENYSEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEVEKENYSEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEVEKENYSEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TEVEKENYSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEG
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEVEKENYSEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEVEKENYSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEG
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TEVEKENYSEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TEVEKENYSEGTIPUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TEVEKENYSEGTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEVEKENYSEGTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEVEKENYSEGTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEVEKENYSEGTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEVEKENYSEGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEVEKENYSEGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TEVEKENYSEGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEGTIPUS
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEVEKENYSEGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEGTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEVEKENYSEGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEGTIPUS
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TEVEKENYSEGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEVEKENYSEGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEVEKENYSEGTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FALIUJSAGBEJEGYZES                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FALIUJSAGBEJEGYZES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FALIUJSAGBEJEGYZES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FALIUJSAGBEJEGYZES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FALIUJSAGBEJEGYZES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FALIUJSAGBEJEGYZES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FALIUJSAGBEJEGYZES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FALIUJSAGBEJEGYZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGBEJEGYZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGBEJEGYZES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FALIUJSAGBEJEGYZES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGBEJEGYZES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGBEJEGYZES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FALIUJSAGBEJEGYZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGBEJEGYZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGBEJEGYZES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FALIUJSAGBEJEGYZES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGBEJEGYZES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGBEJEGYZES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FALIUJSAGLATOGATTOTSAG                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FALIUJSAGLATOGATTOTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FALIUJSAGLATOGATTOTSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FALIUJSAGLATOGATTOTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGLATOGATTOTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FALIUJSAGLATOGATTOTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGLATOGATTOTSAG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FALIUJSAGLATOGATTOTSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGLATOGATTOTSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FALIUJSAGLATOGATTOTSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FALIUJSAGLATOGATTOTSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_FALIUJSAGLATOGATTOTSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PEDAGOGUSELETPALYAMODELL                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSELETPALYAMODELL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PEDAGOGUSELETPALYAMODELL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PEDAGOGUSELETPALYAMODELL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSELETPALYAMODELL
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSELETPALYAMODELL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSELETPALYAMODELL
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PEDAGOGUSELETPALYAMODELL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSELETPALYAMODELL
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PEDAGOGUSELETPALYAMODELL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PEDAGOGUSELETPALYAMODELL_OSSZES
        AS
        SELECT *
        FROM dbo.T_PEDAGOGUSELETPALYAMODELL'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ELETPALYAMODELLFOKOZATTIPUS                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELETPALYAMODELLFOKOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELETPALYAMODELLFOKOZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ELETPALYAMODELLFOKOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLFOKOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLFOKOZATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ELETPALYAMODELLFOKOZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLFOKOZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLFOKOZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLFOKOZATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ELETPALYAMODELLSTATUSZOK                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELETPALYAMODELLSTATUSZOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ELETPALYAMODELLSTATUSZOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ELETPALYAMODELLSTATUSZOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLSTATUSZOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ELETPALYAMODELLSTATUSZOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLSTATUSZOK
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ELETPALYAMODELLSTATUSZOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLSTATUSZOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ELETPALYAMODELLSTATUSZOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ELETPALYAMODELLSTATUSZOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ELETPALYAMODELLSTATUSZOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESEMENYZARADEKTIPUS                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESEMENYZARADEKTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYZARADEKTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESEMENYZARADEKTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYZARADEKTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYZARADEKTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYZARADEKTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESEMENYZARADEKTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYZARADEKTIPUS
        AS
        SELECT *
        FROM dbo.T_ESEMENYZARADEKTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYZARADEKTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYZARADEKTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYZARADEKTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESEMENYZARADEKTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYZARADEKTIPUS
        AS
        SELECT *
        FROM dbo.T_ESEMENYZARADEKTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYZARADEKTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYZARADEKTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYZARADEKTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOMENTESSEG                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOMENTESSEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMENTESSEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOMENTESSEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMENTESSEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMENTESSEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMENTESSEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOMENTESSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMENTESSEG
        AS
        SELECT *
        FROM dbo.T_TANULOMENTESSEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOMENTESSEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMENTESSEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMENTESSEG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOMENTESSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMENTESSEG
        AS
        SELECT *
        FROM dbo.T_TANULOMENTESSEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOMENTESSEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMENTESSEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMENTESSEG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NAPLOELLENORZES                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NAPLOELLENORZES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPLOELLENORZES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NAPLOELLENORZES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPLOELLENORZES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPLOELLENORZES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPLOELLENORZES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NAPLOELLENORZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPLOELLENORZES
        AS
        SELECT *
        FROM dbo.T_NAPLOELLENORZES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NAPLOELLENORZES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPLOELLENORZES_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPLOELLENORZES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NAPLOELLENORZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPLOELLENORZES
        AS
        SELECT *
        FROM dbo.T_NAPLOELLENORZES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NAPLOELLENORZES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPLOELLENORZES_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPLOELLENORZES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IGAZOLAS                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IGAZOLAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IGAZOLAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IGAZOLAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLAS
        AS
        SELECT *
        FROM dbo.T_IGAZOLAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IGAZOLAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLAS
        AS
        SELECT *
        FROM dbo.T_IGAZOLAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ORALATOGATAS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ORALATOGATAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORALATOGATAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORALATOGATAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORALATOGATAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORALATOGATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORALATOGATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ORALATOGATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORALATOGATAS
        AS
        SELECT *
        FROM dbo.T_ORALATOGATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORALATOGATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORALATOGATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORALATOGATAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORALATOGATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORALATOGATAS
        AS
        SELECT *
        FROM dbo.T_ORALATOGATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ORALATOGATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORALATOGATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORALATOGATAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSZTALYZATERTEKELES                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSZTALYZATERTEKELES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYZATERTEKELES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYZATERTEKELES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYZATERTEKELES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYZATERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYZATERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSZTALYZATERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATERTEKELES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYZATERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATERTEKELES
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYZATERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATERTEKELES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYZATERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATERTEKELES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MAGATARTASERTEKELESTIPUS                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MAGATARTASERTEKELESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MAGATARTASERTEKELESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MAGATARTASERTEKELESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MAGATARTASERTEKELESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MAGATARTASERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MAGATARTASERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MAGATARTASERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGATARTASERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_MAGATARTASERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MAGATARTASERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGATARTASERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MAGATARTASERTEKELESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MAGATARTASERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGATARTASERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_MAGATARTASERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MAGATARTASERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGATARTASERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MAGATARTASERTEKELESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSZTALYFONOKIERTEKELES                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSZTALYFONOKIERTEKELES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYFONOKIERTEKELES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYFONOKIERTEKELES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYFONOKIERTEKELES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYFONOKIERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYFONOKIERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSZTALYFONOKIERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYFONOKIERTEKELES
        AS
        SELECT *
        FROM dbo.T_OSZTALYFONOKIERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYFONOKIERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYFONOKIERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYFONOKIERTEKELES
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYFONOKIERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYFONOKIERTEKELES
        AS
        SELECT *
        FROM dbo.T_OSZTALYFONOKIERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYFONOKIERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYFONOKIERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYFONOKIERTEKELES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZORGALOMERTEKELESTIPUS                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZORGALOMERTEKELESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZORGALOMERTEKELESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZORGALOMERTEKELESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZORGALOMERTEKELESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZORGALOMERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZORGALOMERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZORGALOMERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZORGALOMERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_SZORGALOMERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZORGALOMERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZORGALOMERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZORGALOMERTEKELESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZORGALOMERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZORGALOMERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_SZORGALOMERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZORGALOMERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZORGALOMERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZORGALOMERTEKELESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOESEMENY                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOESEMENY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOESEMENY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOESEMENY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOESEMENY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOESEMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOESEMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_TANULOESEMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOESEMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESEMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOESEMENY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_TANULOESEMENY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOESEMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOESEMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOESEMENY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESEMENYTIPUS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESEMENYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESEMENYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESEMENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYTIPUS
        AS
        SELECT *
        FROM dbo.T_ESEMENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESEMENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYTIPUS
        AS
        SELECT *
        FROM dbo.T_ESEMENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IGAZOLASTIPUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IGAZOLASTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLASTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IGAZOLASTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLASTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IGAZOLASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLASTIPUS
        AS
        SELECT *
        FROM dbo.T_IGAZOLASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLASTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IGAZOLASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLASTIPUS
        AS
        SELECT *
        FROM dbo.T_IGAZOLASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLASTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CSENGETESIRENDORA                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CSENGETESIRENDORA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSENGETESIRENDORA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSENGETESIRENDORA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSENGETESIRENDORA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSENGETESIRENDORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSENGETESIRENDORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CSENGETESIRENDORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIRENDORA
        AS
        SELECT *
        FROM dbo.T_CSENGETESIRENDORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSENGETESIRENDORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIRENDORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSENGETESIRENDORA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSENGETESIRENDORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIRENDORA
        AS
        SELECT *
        FROM dbo.T_CSENGETESIRENDORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CSENGETESIRENDORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIRENDORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSENGETESIRENDORA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MULASZTASTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MULASZTASTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MULASZTASTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MULASZTASTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MULASZTASTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MULASZTASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MULASZTASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MULASZTASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASTIPUS
        AS
        SELECT *
        FROM dbo.T_MULASZTASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MULASZTASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MULASZTASTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MULASZTASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASTIPUS
        AS
        SELECT *
        FROM dbo.T_MULASZTASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MULASZTASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MULASZTASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MULASZTASTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOMULASZTAS                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOMULASZTAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMULASZTAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOMULASZTAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOMULASZTAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMULASZTAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOMULASZTAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOMULASZTAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTAS
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOMULASZTAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOMULASZTAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTAS
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOMULASZTAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOMULASZTAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOMULASZTAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTEKELESMOD                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTEKELESMOD', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESMOD'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTEKELESMOD_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESMOD_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESMOD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESMOD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTEKELESMOD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMOD
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMOD
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESMOD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMOD_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMOD
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTEKELESMOD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMOD
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMOD
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESMOD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESMOD_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESMOD'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSZTALYZATTIPUS                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSZTALYZATTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYZATTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYZATTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYZATTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYZATTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSZTALYZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATTIPUS
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYZATTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATTIPUS
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYZATTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYZATTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYZATTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTEKELESTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTEKELESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTEKELESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTEKELESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTEKELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTEKELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTEKELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTEKELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTEKELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTEKELESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOERTEKELES                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOERTEKELES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOERTEKELES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOERTEKELES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOERTEKELES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOERTEKELES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOERTEKELES
        AS
        SELECT *
        FROM dbo.T_TANULOERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOERTEKELES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOERTEKELES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOERTEKELES
        AS
        SELECT *
        FROM dbo.T_TANULOERTEKELES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOERTEKELES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOERTEKELES_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOERTEKELES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANITASIORA                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANITASIORA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANITASIORA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANITASIORA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANITASIORA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANITASIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANITASIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANITASIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANITASIORA
        AS
        SELECT *
        FROM dbo.T_TANITASIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANITASIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANITASIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANITASIORA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANITASIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANITASIORA
        AS
        SELECT *
        FROM dbo.T_TANITASIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANITASIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANITASIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANITASIORA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HELYETTESITESTIPUS                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HELYETTESITESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HELYETTESITESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HELYETTESITESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HELYETTESITESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HELYETTESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HELYETTESITESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HELYETTESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HELYETTESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HELYETTESITESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESTIPUS
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HELYETTESITESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HELYETTESITESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HELYETTESITESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NAPTARINAP                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NAPTARINAP', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARINAP'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NAPTARINAP_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARINAP_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTARINAP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTARINAP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NAPTARINAP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NAPTARINAP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NAPTARINAP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NAPTARINAP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANMENET                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANMENET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANMENET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANMENET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANMENET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANMENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANMENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANMENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANMENET
        AS
        SELECT *
        FROM dbo.T_TANMENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANMENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANMENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANMENET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANMENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANMENET
        AS
        SELECT *
        FROM dbo.T_TANMENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANMENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANMENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANMENET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ORARENDIORA                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ORARENDIORA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORARENDIORA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORARENDIORA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORARENDIORA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORARENDIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORARENDIORA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ORARENDIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORARENDIORA
        AS
        SELECT *
        FROM dbo.T_ORARENDIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORARENDIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORARENDIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORARENDIORA
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORARENDIORA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORARENDIORA
        AS
        SELECT *
        FROM dbo.T_ORARENDIORA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ORARENDIORA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORARENDIORA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORARENDIORA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULOCSOPORT                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULOCSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOCSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULOCSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULOCSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULOCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULOCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOCSOPORT
        AS
        SELECT *
        FROM dbo.T_TANULOCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULOCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOCSOPORT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULOCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOCSOPORT
        AS
        SELECT *
        FROM dbo.T_TANULOCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULOCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULOCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULOCSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CIMTARCSOPORT                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CIMTARCSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTARCSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CIMTARCSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTARCSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTARCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTARCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CIMTARCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTARCSOPORT
        AS
        SELECT *
        FROM dbo.T_CIMTARCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CIMTARCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTARCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTARCSOPORT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CIMTARCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTARCSOPORT
        AS
        SELECT *
        FROM dbo.T_CIMTARCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CIMTARCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTARCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTARCSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CIMTAR                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CIMTAR', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTAR'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CIMTAR_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTAR_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTAR' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTAR' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CIMTAR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTAR
        AS
        SELECT *
        FROM dbo.T_CIMTAR
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CIMTAR_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTAR_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTAR
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CIMTAR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTAR
        AS
        SELECT *
        FROM dbo.T_CIMTAR
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CIMTAR_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTAR_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTAR'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CSENGETESIREND                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CSENGETESIREND', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSENGETESIREND'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSENGETESIREND_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSENGETESIREND_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSENGETESIREND' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSENGETESIREND' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CSENGETESIREND */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIREND
        AS
        SELECT *
        FROM dbo.T_CSENGETESIREND
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSENGETESIREND_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIREND_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSENGETESIREND
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSENGETESIREND */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIREND
        AS
        SELECT *
        FROM dbo.T_CSENGETESIREND
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CSENGETESIREND_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSENGETESIREND_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSENGETESIREND'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HETNAPJATIPUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HETNAPJATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HETNAPJATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HETNAPJATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HETNAPJATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HETNAPJATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HETNAPJATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HETNAPJATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETNAPJATIPUS
        AS
        SELECT *
        FROM dbo.T_HETNAPJATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HETNAPJATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETNAPJATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HETNAPJATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HETNAPJATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETNAPJATIPUS
        AS
        SELECT *
        FROM dbo.T_HETNAPJATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HETNAPJATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETNAPJATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HETNAPJATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANEVRENDJE                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANEVRENDJE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANEVRENDJE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANEVRENDJE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANEVRENDJE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANEVRENDJE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANEVRENDJE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANEVRENDJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEVRENDJE
        AS
        SELECT *
        FROM dbo.T_TANEVRENDJE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANEVRENDJE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEVRENDJE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANEVRENDJE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANEVRENDJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEVRENDJE
        AS
        SELECT *
        FROM dbo.T_TANEVRENDJE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANEVRENDJE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEVRENDJE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANEVRENDJE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HETIRENDTIPUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HETIRENDTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HETIRENDTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HETIRENDTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HETIRENDTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HETIRENDTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HETIRENDTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HETIRENDTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETIRENDTIPUS
        AS
        SELECT *
        FROM dbo.T_HETIRENDTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HETIRENDTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETIRENDTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HETIRENDTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HETIRENDTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETIRENDTIPUS
        AS
        SELECT *
        FROM dbo.T_HETIRENDTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HETIRENDTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HETIRENDTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HETIRENDTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NAPTIPUS                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NAPTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NAPTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NAPTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NAPTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTIPUS
        AS
        SELECT *
        FROM dbo.T_NAPTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NAPTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NAPTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTIPUS
        AS
        SELECT *
        FROM dbo.T_NAPTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NAPTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FOGLALKOZASTIPUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZASTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZASTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZASTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZASTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZASTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FOGLALKOZASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASTIPUS
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FOGLALKOZASTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASTIPUS
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZASTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZASTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZASTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FOGLALKOZAS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FOGLALKOZAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FOGLALKOZAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FOGLALKOZAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FOGLALKOZAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FOGLALKOZAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FOGLALKOZAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TARGYKATEGORIATIPUS                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TARGYKATEGORIATIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TARGYKATEGORIATIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TARGYKATEGORIATIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TARGYKATEGORIATIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TARGYKATEGORIATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TARGYKATEGORIATIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TARGYKATEGORIATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TARGYKATEGORIATIPUS
        AS
        SELECT *
        FROM dbo.T_TARGYKATEGORIATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TARGYKATEGORIATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TARGYKATEGORIATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TARGYKATEGORIATIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TARGYKATEGORIATIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TARGYKATEGORIATIPUS
        AS
        SELECT *
        FROM dbo.T_TARGYKATEGORIATIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TARGYKATEGORIATIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TARGYKATEGORIATIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TARGYKATEGORIATIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EVFOLYAMTIPUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EVFOLYAMTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVFOLYAMTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EVFOLYAMTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVFOLYAMTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EVFOLYAMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EVFOLYAMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EVFOLYAMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EVFOLYAMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EVFOLYAMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EVFOLYAMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANTARGY                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGY
        AS
        SELECT *
        FROM dbo.T_TANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTARGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGY
        AS
        SELECT *
        FROM dbo.T_TANTARGY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTARGY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANTERV                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANTERV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTERV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANTERV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTERV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTERV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTERV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANTERV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERV
        AS
        SELECT *
        FROM dbo.T_TANTERV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANTERV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERV_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTERV
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANTERV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERV
        AS
        SELECT *
        FROM dbo.T_TANTERV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANTERV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERV_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTERV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OKTATASINEVELESIFELADAT                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OKTATASINEVELESIFELADAT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OKTATASINEVELESIFELADAT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OKTATASINEVELESIFELADAT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OKTATASINEVELESIFELADAT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OKTATASINEVELESIFELADAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OKTATASINEVELESIFELADAT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OKTATASINEVELESIFELADAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OKTATASINEVELESIFELADAT
        AS
        SELECT *
        FROM dbo.T_OKTATASINEVELESIFELADAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OKTATASINEVELESIFELADAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OKTATASINEVELESIFELADAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OKTATASINEVELESIFELADAT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OKTATASINEVELESIFELADAT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OKTATASINEVELESIFELADAT
        AS
        SELECT *
        FROM dbo.T_OKTATASINEVELESIFELADAT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OKTATASINEVELESIFELADAT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OKTATASINEVELESIFELADAT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OKTATASINEVELESIFELADAT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERTELMIFOGYATEKOSTIPUS                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTELMIFOGYATEKOSTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERTELMIFOGYATEKOSTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERTELMIFOGYATEKOSTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTELMIFOGYATEKOSTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERTELMIFOGYATEKOSTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTELMIFOGYATEKOSTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERTELMIFOGYATEKOSTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS
        AS
        SELECT *
        FROM dbo.T_ERTELMIFOGYATEKOSTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERTELMIFOGYATEKOSTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERTELMIFOGYATEKOSTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERTELMIFOGYATEKOSTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HALLASSERULTTIPUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HALLASSERULTTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HALLASSERULTTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HALLASSERULTTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HALLASSERULTTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HALLASSERULTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HALLASSERULTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HALLASSERULTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HALLASSERULTTIPUS
        AS
        SELECT *
        FROM dbo.T_HALLASSERULTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HALLASSERULTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HALLASSERULTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HALLASSERULTTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HALLASSERULTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HALLASSERULTTIPUS
        AS
        SELECT *
        FROM dbo.T_HALLASSERULTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HALLASSERULTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HALLASSERULTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HALLASSERULTTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LATASSERULTTIPUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LATASSERULTTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LATASSERULTTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LATASSERULTTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LATASSERULTTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LATASSERULTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LATASSERULTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LATASSERULTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LATASSERULTTIPUS
        AS
        SELECT *
        FROM dbo.T_LATASSERULTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LATASSERULTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LATASSERULTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LATASSERULTTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LATASSERULTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LATASSERULTTIPUS
        AS
        SELECT *
        FROM dbo.T_LATASSERULTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LATASSERULTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LATASSERULTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LATASSERULTTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ETKEZESIKEDVEZMENYTIPUS                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ETKEZESIKEDVEZMENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ETKEZESIKEDVEZMENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ETKEZESIKEDVEZMENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS
        AS
        SELECT *
        FROM dbo.T_ETKEZESIKEDVEZMENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ETKEZESIKEDVEZMENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ETKEZESIKEDVEZMENYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ETKEZESIKEDVEZMENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS
        AS
        SELECT *
        FROM dbo.T_ETKEZESIKEDVEZMENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ETKEZESIKEDVEZMENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ETKEZESIKEDVEZMENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ETKEZESIKEDVEZMENYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HATRANYOSHELYZETTIPUS                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HATRANYOSHELYZETTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HATRANYOSHELYZETTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HATRANYOSHELYZETTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HATRANYOSHELYZETTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HATRANYOSHELYZETTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HATRANYOSHELYZETTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HATRANYOSHELYZETTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HATRANYOSHELYZETTIPUS
        AS
        SELECT *
        FROM dbo.T_HATRANYOSHELYZETTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HATRANYOSHELYZETTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HATRANYOSHELYZETTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HATRANYOSHELYZETTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HATRANYOSHELYZETTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HATRANYOSHELYZETTIPUS
        AS
        SELECT *
        FROM dbo.T_HATRANYOSHELYZETTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HATRANYOSHELYZETTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HATRANYOSHELYZETTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_HATRANYOSHELYZETTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_VALLAS                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_VALLAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VALLAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_VALLAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VALLAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VALLAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VALLAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_VALLAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VALLAS
        AS
        SELECT *
        FROM dbo.T_VALLAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_VALLAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VALLAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_VALLAS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_VALLAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VALLAS
        AS
        SELECT *
        FROM dbo.T_VALLAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_VALLAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VALLAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_VALLAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANEV                                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANEV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANEV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANEV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANEV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANEV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANEV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANEV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEV
        AS
        SELECT *
        FROM dbo.T_TANEV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANEV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEV_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANEV
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANEV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEV
        AS
        SELECT *
        FROM dbo.T_TANEV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANEV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANEV_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANEV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSZTALYCSOPORT                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALYCSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSZTALYCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYCSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYCSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OSZTALY                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OSZTALY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OSZTALY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OSZTALY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALY
        AS
        SELECT *
        FROM dbo.T_OSZTALY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALY_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALY
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALY
        AS
        SELECT *
        FROM dbo.T_OSZTALY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OSZTALY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALY_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANTERVIJELLEG                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANTERVIJELLEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTERVIJELLEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANTERVIJELLEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANTERVIJELLEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTERVIJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANTERVIJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANTERVIJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERVIJELLEG
        AS
        SELECT *
        FROM dbo.T_TANTERVIJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANTERVIJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERVIJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTERVIJELLEG
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANTERVIJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERVIJELLEG
        AS
        SELECT *
        FROM dbo.T_TANTERVIJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANTERVIJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANTERVIJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANTERVIJELLEG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TESTNEVELESTIPUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TESTNEVELESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TESTNEVELESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TESTNEVELESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TESTNEVELESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TESTNEVELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TESTNEVELESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TESTNEVELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TESTNEVELESTIPUS
        AS
        SELECT *
        FROM dbo.T_TESTNEVELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TESTNEVELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TESTNEVELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TESTNEVELESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TESTNEVELESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TESTNEVELESTIPUS
        AS
        SELECT *
        FROM dbo.T_TESTNEVELESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TESTNEVELESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TESTNEVELESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TESTNEVELESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESZKOZJELLEG                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESZKOZJELLEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZJELLEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESZKOZJELLEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZJELLEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESZKOZJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZJELLEG
        AS
        SELECT *
        FROM dbo.T_ESZKOZJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZJELLEG
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESZKOZJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZJELLEG
        AS
        SELECT *
        FROM dbo.T_ESZKOZJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZJELLEG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CSOPORT                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CSOPORT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSOPORT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORT
        AS
        SELECT *
        FROM dbo.T_CSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSOPORT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORT
        AS
        SELECT *
        FROM dbo.T_CSOPORT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CSOPORT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESZKOZCEL                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESZKOZCEL', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZCEL'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESZKOZCEL_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZCEL_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZCEL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZCEL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESZKOZCEL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZCEL
        AS
        SELECT *
        FROM dbo.T_ESZKOZCEL
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZCEL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZCEL_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZCEL
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESZKOZCEL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZCEL
        AS
        SELECT *
        FROM dbo.T_ESZKOZCEL
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZCEL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZCEL_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZCEL'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MERTEKEGYSEGTIPUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MERTEKEGYSEGTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MERTEKEGYSEGTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MERTEKEGYSEGTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MERTEKEGYSEGTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MERTEKEGYSEGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MERTEKEGYSEGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MERTEKEGYSEGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MERTEKEGYSEGTIPUS
        AS
        SELECT *
        FROM dbo.T_MERTEKEGYSEGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MERTEKEGYSEGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MERTEKEGYSEGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MERTEKEGYSEGTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MERTEKEGYSEGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MERTEKEGYSEGTIPUS
        AS
        SELECT *
        FROM dbo.T_MERTEKEGYSEGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MERTEKEGYSEGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MERTEKEGYSEGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MERTEKEGYSEGTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_INTEZMENYADATOK                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_INTEZMENYADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_INTEZMENYADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INTEZMENYADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INTEZMENYADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_INTEZMENYADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATOK
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_INTEZMENYADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATOK
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_INTEZMENYADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INTEZMENYADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_INTEZMENYADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FENNTARTOTIPUS                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FENNTARTOTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FENNTARTOTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FENNTARTOTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FENNTARTOTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FENNTARTOTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FENNTARTOTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FENNTARTOTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FENNTARTOTIPUS
        AS
        SELECT *
        FROM dbo.T_FENNTARTOTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FENNTARTOTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FENNTARTOTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FENNTARTOTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FENNTARTOTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FENNTARTOTIPUS
        AS
        SELECT *
        FROM dbo.T_FENNTARTOTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FENNTARTOTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FENNTARTOTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FENNTARTOTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CSOPORTTIPUS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CSOPORTTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSOPORTTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CSOPORTTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSOPORTTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CSOPORTTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORTTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ROKONSAGIFOK                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ROKONSAGIFOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ROKONSAGIFOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ROKONSAGIFOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ROKONSAGIFOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ROKONSAGIFOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ROKONSAGIFOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ROKONSAGIFOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ROKONSAGIFOK
        AS
        SELECT *
        FROM dbo.T_ROKONSAGIFOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ROKONSAGIFOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ROKONSAGIFOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ROKONSAGIFOK
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ROKONSAGIFOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ROKONSAGIFOK
        AS
        SELECT *
        FROM dbo.T_ROKONSAGIFOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ROKONSAGIFOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ROKONSAGIFOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ROKONSAGIFOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TANULO                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TANULO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TANULO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TANULO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO
        AS
        SELECT *
        FROM dbo.T_TANULO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULO
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO
        AS
        SELECT *
        FROM dbo.T_TANULO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TANULO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_GONDVISELO                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_GONDVISELO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GONDVISELO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_GONDVISELO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_GONDVISELO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GONDVISELO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_GONDVISELO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_GONDVISELO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELO
        AS
        SELECT *
        FROM dbo.T_GONDVISELO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_GONDVISELO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELO_OSSZES
        AS
        SELECT *
        FROM dbo.T_GONDVISELO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_GONDVISELO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELO
        AS
        SELECT *
        FROM dbo.T_GONDVISELO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_GONDVISELO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_GONDVISELO_OSSZES
        AS
        SELECT *
        FROM dbo.T_GONDVISELO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUNKAKORTIPUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUNKAKORTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAKORTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUNKAKORTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAKORTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAKORTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAKORTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUNKAKORTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAKORTIPUS
        AS
        SELECT *
        FROM dbo.T_MUNKAKORTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUNKAKORTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAKORTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAKORTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUNKAKORTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAKORTIPUS
        AS
        SELECT *
        FROM dbo.T_MUNKAKORTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUNKAKORTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAKORTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAKORTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUKODESIHELY                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUKODESIHELY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUKODESIHELY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUKODESIHELY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUKODESIHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELY
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUKODESIHELY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELY
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUKODESIHELY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUKODESIHELY_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUKODESIHELY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ALKALMAZOTT                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ALKALMAZOTT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ALKALMAZOTT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ALKALMAZOTT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ALKALMAZOTT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ALKALMAZOTT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ALKALMAZOTT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ALKALMAZOTT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALKALMAZOTT
        AS
        SELECT *
        FROM dbo.T_ALKALMAZOTT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ALKALMAZOTT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALKALMAZOTT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ALKALMAZOTT
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ALKALMAZOTT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALKALMAZOTT
        AS
        SELECT *
        FROM dbo.T_ALKALMAZOTT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ALKALMAZOTT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALKALMAZOTT_OSSZES
        AS
        SELECT *
        FROM dbo.T_ALKALMAZOTT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ANYANYELV                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ANYANYELV', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ANYANYELV'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ANYANYELV_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ANYANYELV_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ANYANYELV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ANYANYELV' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ANYANYELV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ANYANYELV
        AS
        SELECT *
        FROM dbo.T_ANYANYELV
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ANYANYELV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ANYANYELV_OSSZES
        AS
        SELECT *
        FROM dbo.T_ANYANYELV
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ANYANYELV */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ANYANYELV
        AS
        SELECT *
        FROM dbo.T_ANYANYELV
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ANYANYELV_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ANYANYELV_OSSZES
        AS
        SELECT *
        FROM dbo.T_ANYANYELV'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IGAZOLVANYTIPUS                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IGAZOLVANYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLVANYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IGAZOLVANYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IGAZOLVANYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLVANYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IGAZOLVANYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IGAZOLVANYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLVANYTIPUS
        AS
        SELECT *
        FROM dbo.T_IGAZOLVANYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLVANYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLVANYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLVANYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IGAZOLVANYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLVANYTIPUS
        AS
        SELECT *
        FROM dbo.T_IGAZOLVANYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IGAZOLVANYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IGAZOLVANYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IGAZOLVANYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUNKAVISZONYTIPUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUNKAVISZONYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAVISZONYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUNKAVISZONYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAVISZONYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAVISZONYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAVISZONYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUNKAVISZONYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYTIPUS
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUNKAVISZONYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUNKAVISZONYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYTIPUS
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUNKAVISZONYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TEREM                                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TEREM', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEREM_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEREM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEREM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TEREM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM
        AS
        SELECT *
        FROM dbo.T_TEREM
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEREM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREM
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEREM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM
        AS
        SELECT *
        FROM dbo.T_TEREM
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TEREM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREM'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESZKOZTIPUS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESZKOZTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESZKOZTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESZKOZTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZTIPUS
        AS
        SELECT *
        FROM dbo.T_ESZKOZTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESZKOZTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZTIPUS
        AS
        SELECT *
        FROM dbo.T_ESZKOZTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESZKOZKATEGORIA                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESZKOZKATEGORIA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZKATEGORIA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESZKOZKATEGORIA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZKATEGORIA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZKATEGORIA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZKATEGORIA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESZKOZKATEGORIA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZKATEGORIA
        AS
        SELECT *
        FROM dbo.T_ESZKOZKATEGORIA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZKATEGORIA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZKATEGORIA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZKATEGORIA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESZKOZKATEGORIA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZKATEGORIA
        AS
        SELECT *
        FROM dbo.T_ESZKOZKATEGORIA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZKATEGORIA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZKATEGORIA_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZKATEGORIA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESZKOZ                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESZKOZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESZKOZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESZKOZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESZKOZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESZKOZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZ
        AS
        SELECT *
        FROM dbo.T_ESZKOZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZ
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESZKOZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZ
        AS
        SELECT *
        FROM dbo.T_ESZKOZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESZKOZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESZKOZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESZKOZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_INGYENESTANKONYVELLATAS                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_INGYENESTANKONYVELLATAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INGYENESTANKONYVELLATAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_INGYENESTANKONYVELLATAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_INGYENESTANKONYVELLATAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INGYENESTANKONYVELLATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_INGYENESTANKONYVELLATAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_INGYENESTANKONYVELLATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INGYENESTANKONYVELLATAS
        AS
        SELECT *
        FROM dbo.T_INGYENESTANKONYVELLATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_INGYENESTANKONYVELLATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INGYENESTANKONYVELLATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_INGYENESTANKONYVELLATAS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_INGYENESTANKONYVELLATAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INGYENESTANKONYVELLATAS
        AS
        SELECT *
        FROM dbo.T_INGYENESTANKONYVELLATAS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_INGYENESTANKONYVELLATAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_INGYENESTANKONYVELLATAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_INGYENESTANKONYVELLATAS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TEREMTIPUS                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TEREMTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREMTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEREMTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREMTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEREMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TEREMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TEREMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREMTIPUS
        AS
        SELECT *
        FROM dbo.T_TEREMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEREMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREMTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEREMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREMTIPUS
        AS
        SELECT *
        FROM dbo.T_TEREMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TEREMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREMTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MAGANTANULOSAGOKA                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MAGANTANULOSAGOKA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MAGANTANULOSAGOKA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MAGANTANULOSAGOKA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MAGANTANULOSAGOKA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MAGANTANULOSAGOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MAGANTANULOSAGOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MAGANTANULOSAGOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGANTANULOSAGOKA
        AS
        SELECT *
        FROM dbo.T_MAGANTANULOSAGOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MAGANTANULOSAGOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGANTANULOSAGOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_MAGANTANULOSAGOKA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MAGANTANULOSAGOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGANTANULOSAGOKA
        AS
        SELECT *
        FROM dbo.T_MAGANTANULOSAGOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MAGANTANULOSAGOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MAGANTANULOSAGOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_MAGANTANULOSAGOKA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SERVERSTATISTICS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SERVERSTATISTICS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SERVERSTATISTICS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SERVERSTATISTICS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SERVERSTATISTICS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SERVERSTATISTICS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SERVERSTATISTICS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SERVERSTATISTICS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SERVERSTATISTICS
        AS
        SELECT *
        FROM dbo.T_SERVERSTATISTICS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SERVERSTATISTICS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SERVERSTATISTICS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SERVERSTATISTICS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SERVERSTATISTICS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SERVERSTATISTICS
        AS
        SELECT *
        FROM dbo.T_SERVERSTATISTICS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SERVERSTATISTICS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SERVERSTATISTICS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SERVERSTATISTICS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENTITYATTRIBUTEHISTORY                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENTITYATTRIBUTEHISTORY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENTITYATTRIBUTEHISTORY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENTITYATTRIBUTEHISTORY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENTITYATTRIBUTEHISTORY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENTITYATTRIBUTEHISTORY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENTITYATTRIBUTEHISTORY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENTITYATTRIBUTEHISTORY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYATTRIBUTEHISTORY
        AS
        SELECT *
        FROM dbo.T_ENTITYATTRIBUTEHISTORY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENTITYATTRIBUTEHISTORY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYATTRIBUTEHISTORY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENTITYATTRIBUTEHISTORY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENTITYATTRIBUTEHISTORY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYATTRIBUTEHISTORY
        AS
        SELECT *
        FROM dbo.T_ENTITYATTRIBUTEHISTORY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENTITYATTRIBUTEHISTORY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYATTRIBUTEHISTORY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENTITYATTRIBUTEHISTORY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ENTITYHISTORY                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ENTITYHISTORY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENTITYHISTORY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ENTITYHISTORY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ENTITYHISTORY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENTITYHISTORY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ENTITYHISTORY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ENTITYHISTORY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYHISTORY
        AS
        SELECT *
        FROM dbo.T_ENTITYHISTORY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ENTITYHISTORY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYHISTORY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENTITYHISTORY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ENTITYHISTORY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYHISTORY
        AS
        SELECT *
        FROM dbo.T_ENTITYHISTORY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ENTITYHISTORY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ENTITYHISTORY_OSSZES
        AS
        SELECT *
        FROM dbo.T_ENTITYHISTORY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELHASZNALOBELEPES                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOBELEPES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOBELEPES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOBELEPES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOBELEPES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOBELEPES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOBELEPES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELHASZNALOBELEPES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOBELEPES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALOBELEPES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOBELEPES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPES_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LOGEVENTTYPE                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LOGEVENTTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGEVENTTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LOGEVENTTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGEVENTTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGEVENTTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGEVENTTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LOGEVENTTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGEVENTTYPE
        AS
        SELECT *
        FROM dbo.T_LOGEVENTTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LOGEVENTTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGEVENTTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGEVENTTYPE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LOGEVENTTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGEVENTTYPE
        AS
        SELECT *
        FROM dbo.T_LOGEVENTTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LOGEVENTTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGEVENTTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGEVENTTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LOG                                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LOG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LOG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOG
        AS
        SELECT *
        FROM dbo.T_LOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOG
        AS
        SELECT *
        FROM dbo.T_LOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LOGLEVELTYPE                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LOGLEVELTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGLEVELTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LOGLEVELTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGLEVELTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGLEVELTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGLEVELTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LOGLEVELTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGLEVELTYPE
        AS
        SELECT *
        FROM dbo.T_LOGLEVELTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LOGLEVELTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGLEVELTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGLEVELTYPE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LOGLEVELTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGLEVELTYPE
        AS
        SELECT *
        FROM dbo.T_LOGLEVELTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LOGLEVELTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGLEVELTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGLEVELTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_AUTOMATICMESSAGES                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_AUTOMATICMESSAGES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_AUTOMATICMESSAGES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_AUTOMATICMESSAGES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_AUTOMATICMESSAGES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_AUTOMATICMESSAGES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_AUTOMATICMESSAGES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_AUTOMATICMESSAGES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AUTOMATICMESSAGES
        AS
        SELECT *
        FROM dbo.T_AUTOMATICMESSAGES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_AUTOMATICMESSAGES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AUTOMATICMESSAGES_OSSZES
        AS
        SELECT *
        FROM dbo.T_AUTOMATICMESSAGES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_AUTOMATICMESSAGES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AUTOMATICMESSAGES
        AS
        SELECT *
        FROM dbo.T_AUTOMATICMESSAGES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_AUTOMATICMESSAGES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_AUTOMATICMESSAGES_OSSZES
        AS
        SELECT *
        FROM dbo.T_AUTOMATICMESSAGES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EMAILADATOK                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EMAILADATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILADATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EMAILADATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILADATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILADATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EMAILADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILADATOK
        AS
        SELECT *
        FROM dbo.T_EMAILADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EMAILADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILADATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EMAILADATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILADATOK
        AS
        SELECT *
        FROM dbo.T_EMAILADATOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EMAILADATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILADATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILADATOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIGESTEMAILMESSAGE                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIGESTEMAILMESSAGE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIGESTEMAILMESSAGE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIGESTEMAILMESSAGE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIGESTEMAILMESSAGE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIGESTEMAILMESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIGESTEMAILMESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIGESTEMAILMESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTEMAILMESSAGE
        AS
        SELECT *
        FROM dbo.T_DIGESTEMAILMESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIGESTEMAILMESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTEMAILMESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIGESTEMAILMESSAGE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIGESTEMAILMESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTEMAILMESSAGE
        AS
        SELECT *
        FROM dbo.T_DIGESTEMAILMESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIGESTEMAILMESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTEMAILMESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIGESTEMAILMESSAGE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EMAILHIBALOG                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EMAILHIBALOG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILHIBALOG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EMAILHIBALOG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILHIBALOG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILHIBALOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILHIBALOG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EMAILHIBALOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILHIBALOG
        AS
        SELECT *
        FROM dbo.T_EMAILHIBALOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EMAILHIBALOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILHIBALOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILHIBALOG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EMAILHIBALOG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILHIBALOG
        AS
        SELECT *
        FROM dbo.T_EMAILHIBALOG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EMAILHIBALOG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILHIBALOG_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILHIBALOG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIGESTMESSAGEQUEUE                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIGESTMESSAGEQUEUE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIGESTMESSAGEQUEUE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIGESTMESSAGEQUEUE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIGESTMESSAGEQUEUE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIGESTMESSAGEQUEUE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIGESTMESSAGEQUEUE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIGESTMESSAGEQUEUE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTMESSAGEQUEUE
        AS
        SELECT *
        FROM dbo.T_DIGESTMESSAGEQUEUE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIGESTMESSAGEQUEUE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTMESSAGEQUEUE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIGESTMESSAGEQUEUE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIGESTMESSAGEQUEUE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTMESSAGEQUEUE
        AS
        SELECT *
        FROM dbo.T_DIGESTMESSAGEQUEUE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIGESTMESSAGEQUEUE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIGESTMESSAGEQUEUE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIGESTMESSAGEQUEUE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCCARDBEVONASOKA                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCCARDBEVONASOKA', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCCARDBEVONASOKA'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCCARDBEVONASOKA_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCCARDBEVONASOKA_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCCARDBEVONASOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCCARDBEVONASOKA' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCCARDBEVONASOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARDBEVONASOKA
        AS
        SELECT *
        FROM dbo.T_SCCARDBEVONASOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCCARDBEVONASOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARDBEVONASOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCCARDBEVONASOKA
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCCARDBEVONASOKA */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARDBEVONASOKA
        AS
        SELECT *
        FROM dbo.T_SCCARDBEVONASOKA
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCCARDBEVONASOKA_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARDBEVONASOKA_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCCARDBEVONASOKA'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MEGYE                                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MEGYE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MEGYE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MEGYE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MEGYE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MEGYE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MEGYE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MEGYE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MEGYE
        AS
        SELECT *
        FROM dbo.T_MEGYE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MEGYE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MEGYE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MEGYE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MEGYE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MEGYE
        AS
        SELECT *
        FROM dbo.T_MEGYE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MEGYE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MEGYE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MEGYE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SYSTEMPARAMETERVALUE                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETERVALUE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETERVALUE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETERVALUE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETERVALUE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETERVALUE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETERVALUE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SYSTEMPARAMETERVALUE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERVALUE
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERVALUE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETERVALUE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERVALUE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERVALUE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SYSTEMPARAMETERVALUE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERVALUE
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERVALUE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETERVALUE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERVALUE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERVALUE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EMAILUZENET                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EMAILUZENET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILUZENET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EMAILUZENET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILUZENET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILUZENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILUZENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EMAILUZENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILUZENET
        AS
        SELECT *
        FROM dbo.T_EMAILUZENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EMAILUZENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILUZENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILUZENET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EMAILUZENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILUZENET
        AS
        SELECT *
        FROM dbo.T_EMAILUZENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EMAILUZENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILUZENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILUZENET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELHASZNALOBELEPESTORTENET                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOBELEPESTORTENET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOBELEPESTORTENET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALOBELEPESTORTENET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALOBELEPESTORTENET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOBELEPESTORTENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALOBELEPESTORTENET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELHASZNALOBELEPESTORTENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPESTORTENET
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPESTORTENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOBELEPESTORTENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPESTORTENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPESTORTENET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALOBELEPESTORTENET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPESTORTENET
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPESTORTENET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALOBELEPESTORTENET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALOBELEPESTORTENET_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALOBELEPESTORTENET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_HONAPOK                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_HONAPOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HONAPOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_HONAPOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_HONAPOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HONAPOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_HONAPOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_HONAPOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HONAPOK
        AS
        SELECT *
        FROM dbo.T_HONAPOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_HONAPOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HONAPOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_HONAPOK
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_HONAPOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HONAPOK
        AS
        SELECT *
        FROM dbo.T_HONAPOK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_HONAPOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_HONAPOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_HONAPOK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PAYMENTTITLE_ROLES                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLE_ROLES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLE_ROLES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLE_ROLES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLE_ROLES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLE_ROLES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLE_ROLES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PAYMENTTITLE_ROLES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_ROLES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE_ROLES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLE_ROLES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_ROLES_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE_ROLES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PAYMENTTITLE_ROLES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_ROLES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE_ROLES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLE_ROLES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_ROLES_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE_ROLES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIAKIGAZOLVANYIGENYHIBASTATU                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYHIBASTATU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYHIBASTATU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYHIBASTATU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYHIBASTATU
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYHIBASTATU
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYHIBASTATU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYHIBASTATU
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYHIBASTATU_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYHIBASTATU'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIAKIGAZOLVANYIGENYTIPUS                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IMPOSITIONIMPOSITIONGROUP                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONIMPOSITIONGROUP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONIMPOSITIONGROUP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IMPOSITIONIMPOSITIONGROUP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONIMPOSITIONGROUP
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONIMPOSITIONGROUP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONIMPOSITIONGROUP
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITIONIMPOSITIONGROUP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONIMPOSITIONGROUP
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONIMPOSITIONGROUP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONIMPOSITIONGROUP_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONIMPOSITIONGROUP'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SYSTEMPARAMETERTYPE                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETERTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETERTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETERTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETERTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETERTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETERTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SYSTEMPARAMETERTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERTYPE
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETERTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SYSTEMPARAMETERTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERTYPE
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETERTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETERTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETERTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ONLINEUSER                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ONLINEUSER', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ONLINEUSER'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ONLINEUSER_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ONLINEUSER_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ONLINEUSER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ONLINEUSER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ONLINEUSER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ONLINEUSER
        AS
        SELECT *
        FROM dbo.T_ONLINEUSER
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ONLINEUSER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ONLINEUSER_OSSZES
        AS
        SELECT *
        FROM dbo.T_ONLINEUSER
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ONLINEUSER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ONLINEUSER
        AS
        SELECT *
        FROM dbo.T_ONLINEUSER
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ONLINEUSER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ONLINEUSER_OSSZES
        AS
        SELECT *
        FROM dbo.T_ONLINEUSER'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LOGINLINKS                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LOGINLINKS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGINLINKS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LOGINLINKS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGINLINKS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGINLINKS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGINLINKS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LOGINLINKS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINLINKS
        AS
        SELECT *
        FROM dbo.T_LOGINLINKS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LOGINLINKS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINLINKS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGINLINKS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LOGINLINKS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINLINKS
        AS
        SELECT *
        FROM dbo.T_LOGINLINKS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LOGINLINKS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINLINKS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGINLINKS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LOGINNEWS                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LOGINNEWS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGINNEWS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LOGINNEWS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LOGINNEWS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGINNEWS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LOGINNEWS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LOGINNEWS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINNEWS
        AS
        SELECT *
        FROM dbo.T_LOGINNEWS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LOGINNEWS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINNEWS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGINNEWS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LOGINNEWS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINNEWS
        AS
        SELECT *
        FROM dbo.T_LOGINNEWS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LOGINNEWS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LOGINNEWS_OSSZES
        AS
        SELECT *
        FROM dbo.T_LOGINNEWS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OTPJELENTESSTATUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OTPJELENTESSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESSTATUS
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OTPJELENTESSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESSTATUS
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OTPJELENTESEK                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESEK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESEK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESEK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESEK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESEK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESEK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OTPJELENTESEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESEK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OTPJELENTESEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESEK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_OTPJELENTESTIPUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_OTPJELENTESTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_OTPJELENTESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESTIPUS
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OTPJELENTESTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESTIPUS
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KOZTERULETJELLEG                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KOZTERULETJELLEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KOZTERULETJELLEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KOZTERULETJELLEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KOZTERULETJELLEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KOZTERULETJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KOZTERULETJELLEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KOZTERULETJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZTERULETJELLEG
        AS
        SELECT *
        FROM dbo.T_KOZTERULETJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KOZTERULETJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZTERULETJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_KOZTERULETJELLEG
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KOZTERULETJELLEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZTERULETJELLEG
        AS
        SELECT *
        FROM dbo.T_KOZTERULETJELLEG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KOZTERULETJELLEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KOZTERULETJELLEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_KOZTERULETJELLEG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_APPOINTMENT                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_APPOINTMENT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_APPOINTMENT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_APPOINTMENT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_APPOINTMENT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_APPOINTMENT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_APPOINTMENT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_APPOINTMENT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_APPOINTMENT
        AS
        SELECT *
        FROM dbo.T_APPOINTMENT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_APPOINTMENT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_APPOINTMENT_OSSZES
        AS
        SELECT *
        FROM dbo.T_APPOINTMENT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_APPOINTMENT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_APPOINTMENT
        AS
        SELECT *
        FROM dbo.T_APPOINTMENT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_APPOINTMENT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_APPOINTMENT_OSSZES
        AS
        SELECT *
        FROM dbo.T_APPOINTMENT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_BANK                                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_BANK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BANK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_BANK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BANK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BANK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BANK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_BANK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANK
        AS
        SELECT *
        FROM dbo.T_BANK
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_BANK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANK_OSSZES
        AS
        SELECT *
        FROM dbo.T_BANK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_BANK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANK
        AS
        SELECT *
        FROM dbo.T_BANK
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_BANK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANK_OSSZES
        AS
        SELECT *
        FROM dbo.T_BANK'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_USERPROFILE                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_USERPROFILE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_USERPROFILE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_USERPROFILE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_USERPROFILE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_USERPROFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_USERPROFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_USERPROFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERPROFILE
        AS
        SELECT *
        FROM dbo.T_USERPROFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_USERPROFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERPROFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_USERPROFILE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_USERPROFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERPROFILE
        AS
        SELECT *
        FROM dbo.T_USERPROFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_USERPROFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERPROFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_USERPROFILE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIAKIGAZOLVANYIGENYSTATUSZ                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYSTATUSZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYSTATUSZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCSTICKERSTATUS                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCSTICKERSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTICKERSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCSTICKERSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTICKERSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTICKERSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTICKERSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCSTICKERSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKERSTATUS
        AS
        SELECT *
        FROM dbo.T_SCSTICKERSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCSTICKERSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKERSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTICKERSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCSTICKERSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKERSTATUS
        AS
        SELECT *
        FROM dbo.T_SCSTICKERSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCSTICKERSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKERSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTICKERSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MUNKAVISZONYJELLEGE                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MUNKAVISZONYJELLEGE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAVISZONYJELLEGE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MUNKAVISZONYJELLEGE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MUNKAVISZONYJELLEGE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAVISZONYJELLEGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MUNKAVISZONYJELLEGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MUNKAVISZONYJELLEGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYJELLEGE
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYJELLEGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MUNKAVISZONYJELLEGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYJELLEGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYJELLEGE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MUNKAVISZONYJELLEGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYJELLEGE
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYJELLEGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MUNKAVISZONYJELLEGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MUNKAVISZONYJELLEGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MUNKAVISZONYJELLEGE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_KULFOLDISTATUSZTIPUS                                                  */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_KULFOLDISTATUSZTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KULFOLDISTATUSZTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_KULFOLDISTATUSZTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_KULFOLDISTATUSZTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KULFOLDISTATUSZTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_KULFOLDISTATUSZTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_KULFOLDISTATUSZTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KULFOLDISTATUSZTIPUS
        AS
        SELECT *
        FROM dbo.T_KULFOLDISTATUSZTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_KULFOLDISTATUSZTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KULFOLDISTATUSZTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KULFOLDISTATUSZTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_KULFOLDISTATUSZTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KULFOLDISTATUSZTIPUS
        AS
        SELECT *
        FROM dbo.T_KULFOLDISTATUSZTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_KULFOLDISTATUSZTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_KULFOLDISTATUSZTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_KULFOLDISTATUSZTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_VPOSCONFIG                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_VPOSCONFIG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VPOSCONFIG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_VPOSCONFIG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_VPOSCONFIG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VPOSCONFIG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_VPOSCONFIG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_VPOSCONFIG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VPOSCONFIG
        AS
        SELECT *
        FROM dbo.T_VPOSCONFIG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_VPOSCONFIG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VPOSCONFIG_OSSZES
        AS
        SELECT *
        FROM dbo.T_VPOSCONFIG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_VPOSCONFIG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VPOSCONFIG
        AS
        SELECT *
        FROM dbo.T_VPOSCONFIG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_VPOSCONFIG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_VPOSCONFIG_OSSZES
        AS
        SELECT *
        FROM dbo.T_VPOSCONFIG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SMS                                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SMS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SMS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SMS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SMS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SMS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SMS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SMS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMS
        AS
        SELECT *
        FROM dbo.T_SMS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SMS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SMS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SMS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMS
        AS
        SELECT *
        FROM dbo.T_SMS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SMS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SMS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SMSMESSAGESTATUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SMSMESSAGESTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SMSMESSAGESTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SMSMESSAGESTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SMSMESSAGESTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SMSMESSAGESTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SMSMESSAGESTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SMSMESSAGESTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMSMESSAGESTATUS
        AS
        SELECT *
        FROM dbo.T_SMSMESSAGESTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SMSMESSAGESTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMSMESSAGESTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SMSMESSAGESTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SMSMESSAGESTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMSMESSAGESTATUS
        AS
        SELECT *
        FROM dbo.T_SMSMESSAGESTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SMSMESSAGESTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SMSMESSAGESTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_SMSMESSAGESTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TRANSACTIONANALYSISFILESTATU                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILESTATU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILESTATU' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TRANSACTIONANALYSISFILESTATU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILESTATU
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILESTATU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILESTATU
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TRANSACTIONANALYSISFILESTATU */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILESTATU
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILESTATU_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILESTATU_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILESTATU'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ORSZAGTIPUS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ORSZAGTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORSZAGTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORSZAGTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORSZAGTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORSZAGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ORSZAGTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ORSZAGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORSZAGTIPUS
        AS
        SELECT *
        FROM dbo.T_ORSZAGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORSZAGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORSZAGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORSZAGTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORSZAGTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORSZAGTIPUS
        AS
        SELECT *
        FROM dbo.T_ORSZAGTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ORSZAGTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORSZAGTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORSZAGTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_USERNOTIFICATION                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_USERNOTIFICATION', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_USERNOTIFICATION'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_USERNOTIFICATION_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_USERNOTIFICATION_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_USERNOTIFICATION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_USERNOTIFICATION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_USERNOTIFICATION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERNOTIFICATION
        AS
        SELECT *
        FROM dbo.T_USERNOTIFICATION
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_USERNOTIFICATION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERNOTIFICATION_OSSZES
        AS
        SELECT *
        FROM dbo.T_USERNOTIFICATION
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_USERNOTIFICATION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERNOTIFICATION
        AS
        SELECT *
        FROM dbo.T_USERNOTIFICATION
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_USERNOTIFICATION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_USERNOTIFICATION_OSSZES
        AS
        SELECT *
        FROM dbo.T_USERNOTIFICATION'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ESEMENYSTATUSZ                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ESEMENYSTATUSZ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYSTATUSZ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ESEMENYSTATUSZ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ESEMENYSTATUSZ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ESEMENYSTATUSZ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ESEMENYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_ESEMENYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYSTATUSZ
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ESEMENYSTATUSZ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYSTATUSZ
        AS
        SELECT *
        FROM dbo.T_ESEMENYSTATUSZ
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ESEMENYSTATUSZ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ESEMENYSTATUSZ_OSSZES
        AS
        SELECT *
        FROM dbo.T_ESEMENYSTATUSZ'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TRANSACTIONSTATUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TRANSACTIONSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONSTATUS
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TRANSACTIONSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONSTATUS
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCSTUDENTTEMPORARYCARD                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCSTUDENTTEMPORARYCARD', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTUDENTTEMPORARYCARD'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCSTUDENTTEMPORARYCARD_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTUDENTTEMPORARYCARD_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTUDENTTEMPORARYCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTUDENTTEMPORARYCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCSTUDENTTEMPORARYCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTUDENTTEMPORARYCARD
        AS
        SELECT *
        FROM dbo.T_SCSTUDENTTEMPORARYCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCSTUDENTTEMPORARYCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTUDENTTEMPORARYCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTUDENTTEMPORARYCARD
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCSTUDENTTEMPORARYCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTUDENTTEMPORARYCARD
        AS
        SELECT *
        FROM dbo.T_SCSTUDENTTEMPORARYCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCSTUDENTTEMPORARYCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTUDENTTEMPORARYCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTUDENTTEMPORARYCARD'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCAPPLICATIONFORMBATCH                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCAPPLICATIONFORMBATCH', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCAPPLICATIONFORMBATCH'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCAPPLICATIONFORMBATCH_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCAPPLICATIONFORMBATCH_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCAPPLICATIONFORMBATCH' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCAPPLICATIONFORMBATCH' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCAPPLICATIONFORMBATCH */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCAPPLICATIONFORMBATCH
        AS
        SELECT *
        FROM dbo.T_SCAPPLICATIONFORMBATCH
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCAPPLICATIONFORMBATCH_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCAPPLICATIONFORMBATCH_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCAPPLICATIONFORMBATCH
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCAPPLICATIONFORMBATCH */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCAPPLICATIONFORMBATCH
        AS
        SELECT *
        FROM dbo.T_SCAPPLICATIONFORMBATCH
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCAPPLICATIONFORMBATCH_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCAPPLICATIONFORMBATCH_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCAPPLICATIONFORMBATCH'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DIAKIGAZOLVANYIGENYLES                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYLES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DIAKIGAZOLVANYIGENYLES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYLES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYLES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYLES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYLES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DIAKIGAZOLVANYIGENYLES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYLES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DIAKIGAZOLVANYIGENYLES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DIAKIGAZOLVANYIGENYLES_OSSZES
        AS
        SELECT *
        FROM dbo.T_DIAKIGAZOLVANYIGENYLES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCSTICKER                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCSTICKER', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTICKER'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCSTICKER_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCSTICKER_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTICKER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCSTICKER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCSTICKER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKER
        AS
        SELECT *
        FROM dbo.T_SCSTICKER
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCSTICKER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKER_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTICKER
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCSTICKER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKER
        AS
        SELECT *
        FROM dbo.T_SCSTICKER
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCSTICKER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCSTICKER_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCSTICKER'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCINSET                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCINSET', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCINSET'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCINSET_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCINSET_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCINSET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCINSET' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCINSET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCINSET
        AS
        SELECT *
        FROM dbo.T_SCINSET
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCINSET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCINSET_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCINSET
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCINSET */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCINSET
        AS
        SELECT *
        FROM dbo.T_SCINSET
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCINSET_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCINSET_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCINSET'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCTEMPORARYCARD                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCTEMPORARYCARD', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCTEMPORARYCARD'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCTEMPORARYCARD_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCTEMPORARYCARD_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCTEMPORARYCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCTEMPORARYCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCTEMPORARYCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCTEMPORARYCARD
        AS
        SELECT *
        FROM dbo.T_SCTEMPORARYCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCTEMPORARYCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCTEMPORARYCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCTEMPORARYCARD
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCTEMPORARYCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCTEMPORARYCARD
        AS
        SELECT *
        FROM dbo.T_SCTEMPORARYCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCTEMPORARYCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCTEMPORARYCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCTEMPORARYCARD'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SCCARD                                                                */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SCCARD', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCCARD'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SCCARD_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SCCARD_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SCCARD' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SCCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARD
        AS
        SELECT *
        FROM dbo.T_SCCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SCCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCCARD
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SCCARD */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARD
        AS
        SELECT *
        FROM dbo.T_SCCARD
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SCCARD_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SCCARD_OSSZES
        AS
        SELECT *
        FROM dbo.T_SCCARD'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERRORSTATUS                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERRORSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERRORSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERRORSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERRORSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERRORSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERRORSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERRORSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORSTATUS
        AS
        SELECT *
        FROM dbo.T_ERRORSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERRORSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERRORSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERRORSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORSTATUS
        AS
        SELECT *
        FROM dbo.T_ERRORSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERRORSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERRORSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FEETYPE                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FEETYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FEETYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FEETYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FEETYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FEETYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FEETYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FEETYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEETYPE
        AS
        SELECT *
        FROM dbo.T_FEETYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FEETYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEETYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FEETYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FEETYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEETYPE
        AS
        SELECT *
        FROM dbo.T_FEETYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FEETYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEETYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FEETYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PAYMENTTITLETYPE                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLETYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLETYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLETYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLETYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLETYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLETYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PAYMENTTITLETYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLETYPE
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLETYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLETYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLETYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLETYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PAYMENTTITLETYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLETYPE
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLETYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLETYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLETYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLETYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EMAILTIPUS                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EMAILTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EMAILTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAILTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAILTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EMAILTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILTIPUS
        AS
        SELECT *
        FROM dbo.T_EMAILTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EMAILTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EMAILTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILTIPUS
        AS
        SELECT *
        FROM dbo.T_EMAILTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EMAILTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAILTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAILTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TELEFONTIPUS                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TELEFONTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEFONTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TELEFONTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEFONTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEFONTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEFONTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TELEFONTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFONTIPUS
        AS
        SELECT *
        FROM dbo.T_TELEFONTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TELEFONTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFONTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEFONTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TELEFONTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFONTIPUS
        AS
        SELECT *
        FROM dbo.T_TELEFONTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TELEFONTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFONTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEFONTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PAYINGTYPE                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PAYINGTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYINGTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PAYINGTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYINGTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYINGTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYINGTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PAYINGTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYINGTYPE
        AS
        SELECT *
        FROM dbo.T_PAYINGTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PAYINGTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYINGTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYINGTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PAYINGTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYINGTYPE
        AS
        SELECT *
        FROM dbo.T_PAYINGTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PAYINGTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYINGTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYINGTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ALLAMPOLGARSAG                                                        */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ALLAMPOLGARSAG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ALLAMPOLGARSAG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ALLAMPOLGARSAG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ALLAMPOLGARSAG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ALLAMPOLGARSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ALLAMPOLGARSAG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ALLAMPOLGARSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALLAMPOLGARSAG
        AS
        SELECT *
        FROM dbo.T_ALLAMPOLGARSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ALLAMPOLGARSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALLAMPOLGARSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_ALLAMPOLGARSAG
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ALLAMPOLGARSAG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALLAMPOLGARSAG
        AS
        SELECT *
        FROM dbo.T_ALLAMPOLGARSAG
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ALLAMPOLGARSAG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ALLAMPOLGARSAG_OSSZES
        AS
        SELECT *
        FROM dbo.T_ALLAMPOLGARSAG'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_STUDENTCARDSTATUS                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_STUDENTCARDSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_STUDENTCARDSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_STUDENTCARDSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_STUDENTCARDSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_STUDENTCARDSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_STUDENTCARDSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_STUDENTCARDSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDSTATUS
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_STUDENTCARDSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_STUDENTCARDSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDSTATUS
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_STUDENTCARDSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NATIONALITY                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NATIONALITY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NATIONALITY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NATIONALITY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NATIONALITY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NATIONALITY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NATIONALITY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NATIONALITY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATIONALITY
        AS
        SELECT *
        FROM dbo.T_NATIONALITY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NATIONALITY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATIONALITY_OSSZES
        AS
        SELECT *
        FROM dbo.T_NATIONALITY
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NATIONALITY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATIONALITY
        AS
        SELECT *
        FROM dbo.T_NATIONALITY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NATIONALITY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NATIONALITY_OSSZES
        AS
        SELECT *
        FROM dbo.T_NATIONALITY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MARITALSTATUS                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MARITALSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MARITALSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MARITALSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MARITALSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MARITALSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MARITALSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MARITALSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MARITALSTATUS
        AS
        SELECT *
        FROM dbo.T_MARITALSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MARITALSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MARITALSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MARITALSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MARITALSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MARITALSTATUS
        AS
        SELECT *
        FROM dbo.T_MARITALSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MARITALSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MARITALSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_MARITALSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IMPOSITIONSTATUS                                                      */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSTATUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSTATUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSTATUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSTATUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONSTATUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IMPOSITIONSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSTATUS
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSTATUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITIONSTATUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSTATUS
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSTATUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONSTATUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSTATUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSTATUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_LANGUAGE                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_LANGUAGE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LANGUAGE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_LANGUAGE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_LANGUAGE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LANGUAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_LANGUAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_LANGUAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LANGUAGE
        AS
        SELECT *
        FROM dbo.T_LANGUAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_LANGUAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LANGUAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LANGUAGE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_LANGUAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LANGUAGE
        AS
        SELECT *
        FROM dbo.T_LANGUAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_LANGUAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_LANGUAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_LANGUAGE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CIMTIPUS                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CIMTIPUS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTIPUS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CIMTIPUS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMTIPUS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIMTIPUS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CIMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTIPUS
        AS
        SELECT *
        FROM dbo.T_CIMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CIMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTIPUS
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CIMTIPUS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTIPUS
        AS
        SELECT *
        FROM dbo.T_CIMTIPUS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CIMTIPUS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMTIPUS_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMTIPUS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_NEM                                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_NEM', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEM'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NEM_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NEM_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_NEM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_NEM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEM
        AS
        SELECT *
        FROM dbo.T_NEM
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NEM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEM_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEM
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NEM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEM
        AS
        SELECT *
        FROM dbo.T_NEM
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_NEM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NEM_OSSZES
        AS
        SELECT *
        FROM dbo.T_NEM'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_BANKACCOUNT                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_BANKACCOUNT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BANKACCOUNT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_BANKACCOUNT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_BANKACCOUNT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BANKACCOUNT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_BANKACCOUNT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_BANKACCOUNT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANKACCOUNT
        AS
        SELECT *
        FROM dbo.T_BANKACCOUNT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_BANKACCOUNT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANKACCOUNT_OSSZES
        AS
        SELECT *
        FROM dbo.T_BANKACCOUNT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_BANKACCOUNT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANKACCOUNT
        AS
        SELECT *
        FROM dbo.T_BANKACCOUNT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_BANKACCOUNT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_BANKACCOUNT_OSSZES
        AS
        SELECT *
        FROM dbo.T_BANKACCOUNT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CREDITCARDPAYMENT                                                     */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CREDITCARDPAYMENT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CREDITCARDPAYMENT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CREDITCARDPAYMENT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CREDITCARDPAYMENT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CREDITCARDPAYMENT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CREDITCARDPAYMENT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CREDITCARDPAYMENT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDPAYMENT
        AS
        SELECT *
        FROM dbo.T_CREDITCARDPAYMENT
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CREDITCARDPAYMENT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDPAYMENT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CREDITCARDPAYMENT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CREDITCARDPAYMENT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDPAYMENT
        AS
        SELECT *
        FROM dbo.T_CREDITCARDPAYMENT
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CREDITCARDPAYMENT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDPAYMENT_OSSZES
        AS
        SELECT *
        FROM dbo.T_CREDITCARDPAYMENT'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CREDITCARDREPLY                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CREDITCARDREPLY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CREDITCARDREPLY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CREDITCARDREPLY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CREDITCARDREPLY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CREDITCARDREPLY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CREDITCARDREPLY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CREDITCARDREPLY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDREPLY
        AS
        SELECT *
        FROM dbo.T_CREDITCARDREPLY
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CREDITCARDREPLY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDREPLY_OSSZES
        AS
        SELECT *
        FROM dbo.T_CREDITCARDREPLY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CREDITCARDREPLY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDREPLY
        AS
        SELECT *
        FROM dbo.T_CREDITCARDREPLY
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CREDITCARDREPLY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CREDITCARDREPLY_OSSZES
        AS
        SELECT *
        FROM dbo.T_CREDITCARDREPLY'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SYSTEMPARAMETER                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETER', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETER'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SYSTEMPARAMETER_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SYSTEMPARAMETER_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SYSTEMPARAMETER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SYSTEMPARAMETER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETER
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETER
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETER_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETER
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SYSTEMPARAMETER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETER
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETER
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SYSTEMPARAMETER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SYSTEMPARAMETER_OSSZES
        AS
        SELECT *
        FROM dbo.T_SYSTEMPARAMETER'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_DICTIONARYITEMBASE                                                    */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_DICTIONARYITEMBASE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DICTIONARYITEMBASE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_DICTIONARYITEMBASE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_DICTIONARYITEMBASE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DICTIONARYITEMBASE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_DICTIONARYITEMBASE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_DICTIONARYITEMBASE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DICTIONARYITEMBASE
        AS
        SELECT *
        FROM dbo.T_DICTIONARYITEMBASE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_DICTIONARYITEMBASE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DICTIONARYITEMBASE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DICTIONARYITEMBASE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_DICTIONARYITEMBASE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DICTIONARYITEMBASE
        AS
        SELECT *
        FROM dbo.T_DICTIONARYITEMBASE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_DICTIONARYITEMBASE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_DICTIONARYITEMBASE_OSSZES
        AS
        SELECT *
        FROM dbo.T_DICTIONARYITEMBASE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TELEFON                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TELEFON', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEFON'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TELEFON_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TELEFON_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEFON' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TELEFON' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TELEFON */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFON
        AS
        SELECT *
        FROM dbo.T_TELEFON
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TELEFON_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFON_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEFON
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TELEFON */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFON
        AS
        SELECT *
        FROM dbo.T_TELEFON
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TELEFON_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TELEFON_OSSZES
        AS
        SELECT *
        FROM dbo.T_TELEFON'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FORMTYPE                                                              */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FORMTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORMTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FORMTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORMTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORMTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORMTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FORMTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMTYPE
        AS
        SELECT *
        FROM dbo.T_FORMTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FORMTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORMTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FORMTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMTYPE
        AS
        SELECT *
        FROM dbo.T_FORMTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FORMTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORMTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FORMS                                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FORMS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORMS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FORMS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FORMS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORMS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FORMS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FORMS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMS
        AS
        SELECT *
        FROM dbo.T_FORMS
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FORMS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORMS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FORMS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMS
        AS
        SELECT *
        FROM dbo.T_FORMS
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FORMS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FORMS_OSSZES
        AS
        SELECT *
        FROM dbo.T_FORMS'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IMPOSITIONSHAREDRULES                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSHAREDRULES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSHAREDRULES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSHAREDRULES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSHAREDRULES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONSHAREDRULES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONSHAREDRULES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IMPOSITIONSHAREDRULES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONSHAREDRULES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITIONSHAREDRULES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONSHAREDRULES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IMPOSITIONGROUP                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONGROUP', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONGROUP'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONGROUP_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONGROUP_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONGROUP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITIONGROUP' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IMPOSITIONGROUP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONGROUP
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONGROUP
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONGROUP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONGROUP_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONGROUP
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITIONGROUP */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONGROUP
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONGROUP
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONGROUP_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONGROUP_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONGROUP'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FINANCIALCODE                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FINANCIALCODE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FINANCIALCODE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FINANCIALCODE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FINANCIALCODE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FINANCIALCODE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FINANCIALCODE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FINANCIALCODE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FINANCIALCODE
        AS
        SELECT *
        FROM dbo.T_FINANCIALCODE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FINANCIALCODE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FINANCIALCODE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FINANCIALCODE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FINANCIALCODE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FINANCIALCODE
        AS
        SELECT *
        FROM dbo.T_FINANCIALCODE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FINANCIALCODE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FINANCIALCODE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FINANCIALCODE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FEE                                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FEE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FEE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FEE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FEE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FEE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FEE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FEE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEE
        AS
        SELECT *
        FROM dbo.T_FEE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FEE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FEE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FEE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEE
        AS
        SELECT *
        FROM dbo.T_FEE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FEE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FEE_OSSZES
        AS
        SELECT *
        FROM dbo.T_FEE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_SZEREPKOR                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_SZEREPKOR', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZEREPKOR'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_SZEREPKOR_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_SZEREPKOR_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZEREPKOR' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_SZEREPKOR' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_SZEREPKOR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKOR
        AS
        SELECT *
        FROM dbo.T_SZEREPKOR
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_SZEREPKOR_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKOR_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZEREPKOR
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_SZEREPKOR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKOR
        AS
        SELECT *
        FROM dbo.T_SZEREPKOR
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_SZEREPKOR_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_SZEREPKOR_OSSZES
        AS
        SELECT *
        FROM dbo.T_SZEREPKOR'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_STUDENTCARDTYPE                                                       */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_STUDENTCARDTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_STUDENTCARDTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_STUDENTCARDTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_STUDENTCARDTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_STUDENTCARDTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_STUDENTCARDTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_STUDENTCARDTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDTYPE
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_STUDENTCARDTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_STUDENTCARDTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDTYPE
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_STUDENTCARDTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_STUDENTCARDTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_STUDENTCARDTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_CIM                                                                   */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_CIM', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIM'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CIM_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIM_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_CIM' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_CIM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIM
        AS
        SELECT *
        FROM dbo.T_CIM
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CIM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIM_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIM
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CIM */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIM
        AS
        SELECT *
        FROM dbo.T_CIM
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_CIM_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIM_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIM'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TRANSACTION                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TRANSACTION', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTION'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TRANSACTION_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTION_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TRANSACTION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTION
        AS
        SELECT *
        FROM dbo.T_TRANSACTION
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTION_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTION
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TRANSACTION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTION
        AS
        SELECT *
        FROM dbo.T_TRANSACTION
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTION_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTION'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PARTNER                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PARTNER', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PARTNER'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PARTNER_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PARTNER_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PARTNER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PARTNER' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PARTNER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTNER
        AS
        SELECT *
        FROM dbo.T_PARTNER
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PARTNER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTNER_OSSZES
        AS
        SELECT *
        FROM dbo.T_PARTNER
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PARTNER */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTNER
        AS
        SELECT *
        FROM dbo.T_PARTNER
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PARTNER_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PARTNER_OSSZES
        AS
        SELECT *
        FROM dbo.T_PARTNER'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_ERRORTYPE                                                             */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_ERRORTYPE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERRORTYPE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ERRORTYPE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ERRORTYPE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERRORTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALTANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_ALTANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_ERRORTYPE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_ALINTEZMENYID' 
            ) > 0
    BEGIN
        /* T_ERRORTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORTYPE
        AS
        SELECT *
        FROM dbo.T_ERRORTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ERRORTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERRORTYPE
        WHERE C_ALINTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ERRORTYPE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORTYPE
        AS
        SELECT *
        FROM dbo.T_ERRORTYPE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_ERRORTYPE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ERRORTYPE_OSSZES
        AS
        SELECT *
        FROM dbo.T_ERRORTYPE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_EMAIL                                                                 */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_EMAIL', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAIL'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EMAIL_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EMAIL_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAIL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_EMAIL' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_EMAIL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAIL
        AS
        SELECT *
        FROM dbo.T_EMAIL
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EMAIL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAIL_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAIL
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EMAIL */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAIL
        AS
        SELECT *
        FROM dbo.T_EMAIL
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_EMAIL_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EMAIL_OSSZES
        AS
        SELECT *
        FROM dbo.T_EMAIL'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_FELHASZNALO                                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_FELHASZNALO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_FELHASZNALO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PERSONMESSAGE                                                         */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PERSONMESSAGE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PERSONMESSAGE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PERSONMESSAGE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PERSONMESSAGE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PERSONMESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PERSONMESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PERSONMESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PERSONMESSAGE
        AS
        SELECT *
        FROM dbo.T_PERSONMESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PERSONMESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PERSONMESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PERSONMESSAGE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PERSONMESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PERSONMESSAGE
        AS
        SELECT *
        FROM dbo.T_PERSONMESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PERSONMESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PERSONMESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PERSONMESSAGE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_MESSAGE                                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_MESSAGE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MESSAGE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_MESSAGE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_MESSAGE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_MESSAGE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_MESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGE
        AS
        SELECT *
        FROM dbo.T_MESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_MESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MESSAGE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_MESSAGE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGE
        AS
        SELECT *
        FROM dbo.T_MESSAGE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_MESSAGE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_MESSAGE_OSSZES
        AS
        SELECT *
        FROM dbo.T_MESSAGE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_PAYMENTTITLE                                                          */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_PAYMENTTITLE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_PAYMENTTITLE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_PAYMENTTITLE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_PAYMENTTITLE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_PAYMENTTITLE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_PAYMENTTITLE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_PAYMENTTITLE_OSSZES
        AS
        SELECT *
        FROM dbo.T_PAYMENTTITLE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TRANSACTIONANALYSISFILELINE                                           */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILELINE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILELINE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILELINE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILELINE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILELINE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILELINE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TRANSACTIONANALYSISFILELINE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILELINE
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILELINE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILELINE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILELINE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILELINE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TRANSACTIONANALYSISFILELINE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILELINE
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILELINE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILELINE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILELINE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILELINE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_TRANSACTIONANALYSISFILE                                               */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TRANSACTIONANALYSISFILE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TRANSACTIONANALYSISFILE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_TRANSACTIONANALYSISFILE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_TRANSACTIONANALYSISFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILE
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TRANSACTIONANALYSISFILE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILE
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILE
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_TRANSACTIONANALYSISFILE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TRANSACTIONANALYSISFILE_OSSZES
        AS
        SELECT *
        FROM dbo.T_TRANSACTIONANALYSISFILE'
        EXECUTE sp_executesql @Sql
    END
END


/*============================================================================*/
/* View : T_IMPOSITION                                                            */
/*============================================================================*/
/* Package: Kreta */
IF OBJECT_ID('['+@Schema+'].T_IMPOSITION', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITION'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITION_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITION_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_TANEVID' 
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '
    END
    ELSE 
    BEGIN
        SET @AktivTanev = N''
    END

    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = N'T_IMPOSITION' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME = 'C_INTEZMENYID' 
            ) > 0
    BEGIN
        /* T_IMPOSITION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITION
        AS
        SELECT *
        FROM dbo.T_IMPOSITION
        WHERE '+@AktivTanev+' (TOROLT = ''F'') AND C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITION_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITION
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITION */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITION
        AS
        SELECT *
        FROM dbo.T_IMPOSITION
        WHERE '+@AktivTanev+' (TOROLT = ''F'')'
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITION_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITION_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITION'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_OGOSZTALYCSOPORT_KIZAROCSOPO */

/*============================================================================*/
/* View : T_OGOSZTALYCSOPORT_KIZAROCSOPO                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_OGOSZTALYCSOPORT_KIZAROCSOPO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_OGOSZTALYCSOPORT_KIZAROCSOPO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT_KIZAROCSOPO
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OGOSZTALYCSOPORT_KIZAROCSOPO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO_OSSZES
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT_KIZAROCSOPO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OGOSZTALYCSOPORT_KIZAROCSOPO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OGOSZTALYCSOPORT_KIZAROCSOPO
        AS
        SELECT *
        FROM dbo.T_OGOSZTALYCSOPORT_KIZAROCSOPO'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_OSZTALYCSOPORT_TANULOESEMENY */

/*============================================================================*/
/* View : T_OSZTALYCSOPORT_TANULOESEMENY                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_OSZTALYCSOPORT_TANULOESEMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_OSZTALYCSOPORT_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANULOESEMENY
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYCSOPORT_TANULOESEMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANULOESEMENY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYCSOPORT_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANULOESEMENY'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_JOGOSULTFELHASZNALOK_HOZZARE */

/*============================================================================*/
/* View : T_JOGOSULTFELHASZNALOK_HOZZARE                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_JOGOSULTFELHASZNALOK_HOZZARE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_JOGOSULTFELHASZNALOK_HOZZARE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE
        AS
        SELECT *
        FROM dbo.T_JOGOSULTFELHASZNALOK_HOZZARE
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_JOGOSULTFELHASZNALOK_HOZZARE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGOSULTFELHASZNALOK_HOZZARE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_JOGOSULTFELHASZNALOK_HOZZARE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTFELHASZNALOK_HOZZARE
        AS
        SELECT *
        FROM dbo.T_JOGOSULTFELHASZNALOK_HOZZARE'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_JOGOSULTGONDVISELOK_HOZZAREN */

/*============================================================================*/
/* View : T_JOGOSULTGONDVISELOK_HOZZAREN                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_JOGOSULTGONDVISELOK_HOZZAREN' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_JOGOSULTGONDVISELOK_HOZZAREN */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN
        AS
        SELECT *
        FROM dbo.T_JOGOSULTGONDVISELOK_HOZZAREN
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_JOGOSULTGONDVISELOK_HOZZAREN_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGOSULTGONDVISELOK_HOZZAREN
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_JOGOSULTGONDVISELOK_HOZZAREN */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTGONDVISELOK_HOZZAREN
        AS
        SELECT *
        FROM dbo.T_JOGOSULTGONDVISELOK_HOZZAREN'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_JOGOSULTSAG_FELHASZNALO */

/*============================================================================*/
/* View : T_JOGOSULTSAG_FELHASZNALO                                              */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_JOGOSULTSAG_FELHASZNALO' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_JOGOSULTSAG_FELHASZNALO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG_FELHASZNALO
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_JOGOSULTSAG_FELHASZNALO_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO_OSSZES
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG_FELHASZNALO
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_JOGOSULTSAG_FELHASZNALO */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_JOGOSULTSAG_FELHASZNALO
        AS
        SELECT *
        FROM dbo.T_JOGOSULTSAG_FELHASZNALO'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_EVFOLYAMTIPUS_OKTATASINEVELE */

/*============================================================================*/
/* View : T_EVFOLYAMTIPUS_OKTATASINEVELE                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_EVFOLYAMTIPUS_OKTATASINEVELE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_EVFOLYAMTIPUS_OKTATASINEVELE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS_OKTATASINEVELE
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_EVFOLYAMTIPUS_OKTATASINEVELE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE_OSSZES
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS_OKTATASINEVELE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_EVFOLYAMTIPUS_OKTATASINEVELE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_EVFOLYAMTIPUS_OKTATASINEVELE
        AS
        SELECT *
        FROM dbo.T_EVFOLYAMTIPUS_OKTATASINEVELE'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_TEREM_TANARITANTARGY */

/*============================================================================*/
/* View : T_TEREM_TANARITANTARGY                                                 */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_TEREM_TANARITANTARGY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM_TANARITANTARGY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEREM_TANARITANTARGY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM_TANARITANTARGY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_TEREM_TANARITANTARGY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_TEREM_TANARITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_TANARITANTARGY
        AS
        SELECT *
        FROM dbo.T_TEREM_TANARITANTARGY
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEREM_TANARITANTARGY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_TANARITANTARGY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREM_TANARITANTARGY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEREM_TANARITANTARGY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_TANARITANTARGY
        AS
        SELECT *
        FROM dbo.T_TEREM_TANARITANTARGY'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_TEREM_FOGLALKOZAS */

/*============================================================================*/
/* View : T_TEREM_FOGLALKOZAS                                                    */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_TEREM_FOGLALKOZAS', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM_FOGLALKOZAS'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TEREM_FOGLALKOZAS_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TEREM_FOGLALKOZAS_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_TEREM_FOGLALKOZAS' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_TEREM_FOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_FOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_TEREM_FOGLALKOZAS
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TEREM_FOGLALKOZAS_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_FOGLALKOZAS_OSSZES
        AS
        SELECT *
        FROM dbo.T_TEREM_FOGLALKOZAS
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TEREM_FOGLALKOZAS */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TEREM_FOGLALKOZAS
        AS
        SELECT *
        FROM dbo.T_TEREM_FOGLALKOZAS'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_CSATOLTFELHASZNALOK_CSATOLTJ */

/*============================================================================*/
/* View : T_CSATOLTFELHASZNALOK_CSATOLTJ                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_CSATOLTFELHASZNALOK_CSATOLTJ' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_CSATOLTFELHASZNALOK_CSATOLTJ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ
        AS
        SELECT *
        FROM dbo.T_CSATOLTFELHASZNALOK_CSATOLTJ
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSATOLTFELHASZNALOK_CSATOLTJ_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSATOLTFELHASZNALOK_CSATOLTJ
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSATOLTFELHASZNALOK_CSATOLTJ */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSATOLTFELHASZNALOK_CSATOLTJ
        AS
        SELECT *
        FROM dbo.T_CSATOLTFELHASZNALOK_CSATOLTJ'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_TERMEK_JOGYAKORLATOK */

/*============================================================================*/
/* View : T_TERMEK_JOGYAKORLATOK                                                 */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_TERMEK_JOGYAKORLATOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TERMEK_JOGYAKORLATOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TERMEK_JOGYAKORLATOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TERMEK_JOGYAKORLATOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_TERMEK_JOGYAKORLATOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_TERMEK_JOGYAKORLATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TERMEK_JOGYAKORLATOK
        AS
        SELECT *
        FROM dbo.T_TERMEK_JOGYAKORLATOK
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TERMEK_JOGYAKORLATOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TERMEK_JOGYAKORLATOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_TERMEK_JOGYAKORLATOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TERMEK_JOGYAKORLATOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TERMEK_JOGYAKORLATOK
        AS
        SELECT *
        FROM dbo.T_TERMEK_JOGYAKORLATOK'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_RESZTVEVOK_TEVEKENYSEGEK */

/*============================================================================*/
/* View : T_RESZTVEVOK_TEVEKENYSEGEK                                             */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_RESZTVEVOK_TEVEKENYSEGEK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_RESZTVEVOK_TEVEKENYSEGEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK
        AS
        SELECT *
        FROM dbo.T_RESZTVEVOK_TEVEKENYSEGEK
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_RESZTVEVOK_TEVEKENYSEGEK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK_OSSZES
        AS
        SELECT *
        FROM dbo.T_RESZTVEVOK_TEVEKENYSEGEK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_RESZTVEVOK_TEVEKENYSEGEK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_RESZTVEVOK_TEVEKENYSEGEK
        AS
        SELECT *
        FROM dbo.T_RESZTVEVOK_TEVEKENYSEGEK'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_NAPTARINAP_TEVEKENYSEG */

/*============================================================================*/
/* View : T_NAPTARINAP_TEVEKENYSEG                                               */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_NAPTARINAP_TEVEKENYSEG' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_NAPTARINAP_TEVEKENYSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP_TEVEKENYSEG
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_NAPTARINAP_TEVEKENYSEG_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG_OSSZES
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP_TEVEKENYSEG
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_NAPTARINAP_TEVEKENYSEG */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_NAPTARINAP_TEVEKENYSEG
        AS
        SELECT *
        FROM dbo.T_NAPTARINAP_TEVEKENYSEG'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_CIMZETT_FALIUJSAGBEJEGYZES */

/*============================================================================*/
/* View : T_CIMZETT_FALIUJSAGBEJEGYZES                                           */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_CIMZETT_FALIUJSAGBEJEGYZES' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_CIMZETT_FALIUJSAGBEJEGYZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES
        AS
        SELECT *
        FROM dbo.T_CIMZETT_FALIUJSAGBEJEGYZES
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CIMZETT_FALIUJSAGBEJEGYZES_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES_OSSZES
        AS
        SELECT *
        FROM dbo.T_CIMZETT_FALIUJSAGBEJEGYZES
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CIMZETT_FALIUJSAGBEJEGYZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CIMZETT_FALIUJSAGBEJEGYZES
        AS
        SELECT *
        FROM dbo.T_CIMZETT_FALIUJSAGBEJEGYZES'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_OSZTALYCSOPORT_FALIUJSAGBEJE */

/*============================================================================*/
/* View : T_OSZTALYCSOPORT_FALIUJSAGBEJE                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_OSZTALYCSOPORT_FALIUJSAGBEJE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_OSZTALYCSOPORT_FALIUJSAGBEJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_FALIUJSAGBEJE
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYCSOPORT_FALIUJSAGBEJE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_FALIUJSAGBEJE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYCSOPORT_FALIUJSAGBEJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_FALIUJSAGBEJE
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_FALIUJSAGBEJE'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_TANULO_TANULOESEMENY */

/*============================================================================*/
/* View : T_TANULO_TANULOESEMENY                                                 */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_TANULO_TANULOESEMENY', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULO_TANULOESEMENY'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_TANULO_TANULOESEMENY_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_TANULO_TANULOESEMENY_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_TANULO_TANULOESEMENY' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_TANULO_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_TANULO_TANULOESEMENY
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_TANULO_TANULOESEMENY_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO_TANULOESEMENY_OSSZES
        AS
        SELECT *
        FROM dbo.T_TANULO_TANULOESEMENY
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_TANULO_TANULOESEMENY */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_TANULO_TANULOESEMENY
        AS
        SELECT *
        FROM dbo.T_TANULO_TANULOESEMENY'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_ORAK_TANAROK */

/*============================================================================*/
/* View : T_ORAK_TANAROK                                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_ORAK_TANAROK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORAK_TANAROK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_ORAK_TANAROK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_ORAK_TANAROK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_ORAK_TANAROK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_ORAK_TANAROK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORAK_TANAROK
        AS
        SELECT *
        FROM dbo.T_ORAK_TANAROK
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_ORAK_TANAROK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORAK_TANAROK_OSSZES
        AS
        SELECT *
        FROM dbo.T_ORAK_TANAROK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_ORAK_TANAROK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_ORAK_TANAROK
        AS
        SELECT *
        FROM dbo.T_ORAK_TANAROK'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_OSZTALYCSOPORT_TANEVRENDJE */

/*============================================================================*/
/* View : T_OSZTALYCSOPORT_TANEVRENDJE                                           */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_OSZTALYCSOPORT_TANEVRENDJE' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_OSZTALYCSOPORT_TANEVRENDJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANEVRENDJE
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OSZTALYCSOPORT_TANEVRENDJE_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE_OSSZES
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANEVRENDJE
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OSZTALYCSOPORT_TANEVRENDJE */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OSZTALYCSOPORT_TANEVRENDJE
        AS
        SELECT *
        FROM dbo.T_OSZTALYCSOPORT_TANEVRENDJE'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_CSOPORTOK_OSZTALYOK */

/*============================================================================*/
/* View : T_CSOPORTOK_OSZTALYOK                                                  */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_CSOPORTOK_OSZTALYOK', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTOK_OSZTALYOK'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_CSOPORTOK_OSZTALYOK_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_CSOPORTOK_OSZTALYOK_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_CSOPORTOK_OSZTALYOK' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_CSOPORTOK_OSZTALYOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTOK_OSZTALYOK
        AS
        SELECT *
        FROM dbo.T_CSOPORTOK_OSZTALYOK
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_CSOPORTOK_OSZTALYOK_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTOK_OSZTALYOK_OSSZES
        AS
        SELECT *
        FROM dbo.T_CSOPORTOK_OSZTALYOK
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_CSOPORTOK_OSZTALYOK */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_CSOPORTOK_OSZTALYOK
        AS
        SELECT *
        FROM dbo.T_CSOPORTOK_OSZTALYOK'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_FELHASZNALO_SZEREPKOR */

/*============================================================================*/
/* View : T_FELHASZNALO_SZEREPKOR                                                */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_FELHASZNALO_SZEREPKOR', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALO_SZEREPKOR'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_FELHASZNALO_SZEREPKOR_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_FELHASZNALO_SZEREPKOR_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_FELHASZNALO_SZEREPKOR' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_FELHASZNALO_SZEREPKOR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO_SZEREPKOR
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO_SZEREPKOR
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_FELHASZNALO_SZEREPKOR_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO_SZEREPKOR_OSSZES
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO_SZEREPKOR
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_FELHASZNALO_SZEREPKOR */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_FELHASZNALO_SZEREPKOR
        AS
        SELECT *
        FROM dbo.T_FELHASZNALO_SZEREPKOR'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_OTPJELENTESEK_BANKACCOUNT */

/*============================================================================*/
/* View : T_OTPJELENTESEK_BANKACCOUNT                                            */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_OTPJELENTESEK_BANKACCOUNT' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_OTPJELENTESEK_BANKACCOUNT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK_BANKACCOUNT
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_OTPJELENTESEK_BANKACCOUNT_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT_OSSZES
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK_BANKACCOUNT
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_OTPJELENTESEK_BANKACCOUNT */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_OTPJELENTESEK_BANKACCOUNT
        AS
        SELECT *
        FROM dbo.T_OTPJELENTESEK_BANKACCOUNT'
        EXECUTE sp_executesql @Sql
    END
END

/* VIEW: T_IMPOSITIONSHAREDRULES_PAYMEN */

/*============================================================================*/
/* View : T_IMPOSITIONSHAREDRULES_PAYMEN                                         */
/*============================================================================*/
IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN', 'V') IS NOT NULL BEGIN
    SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN'''
    EXEC sp_executesql @Sql

    IF OBJECT_ID('['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN_OSSZES', 'V') IS NOT NULL BEGIN
        SET @Sql = N'EXEC sp_refreshview ''['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN_OSSZES'''
        EXEC sp_executesql @Sql
    END
END
ELSE BEGIN
    /* Ha nem l�tezik a view, akkor l�trehozzuk */
    IF (SELECT COUNT(1)
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'T_IMPOSITIONSHAREDRULES_PAYMEN' AND TABLE_SCHEMA = 'dbo' AND COLUMN_NAME IN ( 'C_INTEZMENYID', 'C_TANEVID' )
            ) > 0
    BEGIN
        SET @AktivTanev = N' C_TANEVID = '+ CAST(@TanevId as nvarchar) +' AND '

        /* T_IMPOSITIONSHAREDRULES_PAYMEN */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES_PAYMEN
        WHERE '+@AktivTanev+' C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql

        /* T_IMPOSITIONSHAREDRULES_PAYMEN_OSSZES */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN_OSSZES
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES_PAYMEN
        WHERE C_INTEZMENYID = '+CAST(@IntezmenyId as nvarchar)
        EXECUTE sp_executesql @Sql
    END
    ELSE 
    BEGIN
        /* T_IMPOSITIONSHAREDRULES_PAYMEN */
        SET @Sql = N'CREATE VIEW ['+@Schema+'].T_IMPOSITIONSHAREDRULES_PAYMEN
        AS
        SELECT *
        FROM dbo.T_IMPOSITIONSHAREDRULES_PAYMEN'
        EXECUTE sp_executesql @Sql
    END
END

END
GO
