UPDATE TBDD_MODULES SET DB_VERSION = '2.5.2.2' where NAME = 'Global-Indexer' 
GO
IF COL_LENGTH('TBGI_FILES_USER','FILE_HASH') IS NOT NULL
    PRINT 'Column FILE_HASH Exists';
ELSE
    ALTER TABLE TBGI_FILES_USER ADD FILE_HASH VARCHAR(200) DEFAULT ''
GO
USE [DD_ECM_TEST]
GO

ALTER VIEW [dbo].[VWGI_DOCTYPE] AS 
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--T2.NAME AS GROUP_NAME,
	T3.DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_FILESTORE_ID,
	T4.SEQUENCE
FROM
	TBDD_USER T,
	TBDD_GROUPS_USER T1,
	TBDD_GROUPS T2,
	TBDD_USRGRP_DOKTYPE T3,
	TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T1.[USER_ID] AND
	T1.GROUP_ID = T2.GUID AND
	T2.GUID = T3.GROUP_ID AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM TBDD_MODULES WHERE UPPER(SHORT_NAME) = ('GLOBIX')))
UNION
SELECT DISTINCT
	T.GUID AS [USER_ID],
	T.USERNAME,
	--'' AS GROUP_NAME,
	T4.GUID as DOCTYPE_ID,
	T4.BEZEICHNUNG AS DOCTYPE,
	T4.BEZEICHNUNG AS DOCTYPE_ONLY,
	T4.KURZNAME,
	T4.ZIEL_PFAD,
	T4.AKTIV,
	T4.NAMENKONVENTION,
	T4.OBJEKTTYP,
	T4.IDB_FILESTORE_ID,
	T4.SEQUENCE
FROM
	TBDD_USER T,
	TBDD_USER_DOKTYPE T3,
	TBDD_DOKUMENTART T4
WHERE
	T4.AKTIV = 1 AND
	T.GUID = T3.[USER_ID] AND
	T3.DOCTYPE_ID = T4.GUID AND
	T4.GUID in (SELECT DOKART_ID FROM TBDD_DOKUMENTART_MODULE WHERE MODULE_ID = (SELECT GUID FROM TBDD_MODULES WHERE UPPER(SHORT_NAME) = ('GLOBIX')))
GO



