IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_MODULE_LIST]'))
	DROP VIEW [dbo].[V_MODULE_LIST]
GO
CREATE VIEW [dbo].[V_MODULE_LIST] ([MODULE]) AS 
  SELECT DISTINCT DI010327 Module
  FROM DT515 -- Rollen und Arbeitsgebiete - Hauptmodule
  JOIN DT513
  ON (DT515.DI010325 = DT513.DI010324)
  JOIN DT512
  ON (DT513.DI010324 = DT512.DI010332)
  JOIN DT510
  ON (DT512.DI010333 = DT510.DI010320)
  JOIN DT405
  ON (DT515.DI010327 = DT405.DI000123)
  WHERE ((DT510.DI025626 LIKE '39'
  OR DT510.DI025626 LIKE '39PM')
  OR (DT510.DI025626 LIKE '38'
  AND DT513.DI025596 LIKE '39'))
  UNION
  SELECT DISTINCT DI051828
  FROM DT333 --Globale Einstellungen - Hauptmodule
  JOIN DT405
  ON (DT333.DI051828 = DT405.DI000123)
  WHERE DI051827 LIKE 108;
GO
