CREATE OR ALTER VIEW [VWDEX_PROFILE]
as
SELECT
        [CFG_PROFILE].[GUID],
        [CFG_PROFILE].[ACTIVE],
        [CFG_PROFILE].[PROFILE_NAME],
        [CFG_PROFILE].[DESCRIPTION],
        [CFG_PROFILE].[MANDANTOR],
        [CFG_PROFILE].[EXPORT_TYPE],
        [CFG_PROFILE].[EXPORT_NUMBER_SCHEMA],
        [CFG_PROFILE].[DEFAULT_DATA_SEPARATOR],
        CASE 
            WHEN [CFG_PROFILE].[LOG_LEVEL] IS NULL -- In case of using the LOG_LEVEL Parameter
			THEN 'INFO'

            WHEN [CFG_PROFILE].[LOG_LEVEL] NOT IN ('INFO','WARN','ERROR')
			THEN 'INFO'

            ELSE [CFG_PROFILE].[LOG_LEVEL] 
        END       as 'LOG_LEVEL',
        [CFG_PROFILE].[LANGUAGE],
        [CFG_PROFILE].[ADDED_WHO],
        [CFG_PROFILE].[ADDED_WHEN],
        [CFG_PROFILE].[CHANGED_WHO],
        [CFG_PROFILE].[CHANGED_WHEN],
        [RUN_PROFILE].[FIRST_RUN],
        [RUN_PROFILE].[LAST_RUN],
        [RUN_PROFILE].[LAST_BATCH_ID],
        [RUN_PROFILE].[LAST_RESULT]

        FROM      [TBDEX_CFG_PROFILE] as [CFG_PROFILE]
    LEFT JOIN [TBDEX_RUN_PROFILE] as [RUN_PROFILE] ON [CFG_PROFILE].[GUID] = [RUN_PROFILE].[PROFILE_ID];
