IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[V_MODULE_LIST_39]'))
	DROP VIEW [dbo].[V_MODULE_LIST_39]
GO
CREATE VIEW [dbo].[V_MODULE_LIST_39] ([PARENT_ID], [MOD_ID], [TYPE]) AS 
  SELECT [PARENT_ID],
    [MOD_ID],
    [Type]
  FROM
    ( SELECT DISTINCT V_MODULE_LIST.MODULE parent_id,
      DT411.DI000111 mod_id,
      CAST(1 AS float) [Type]
    FROM DT411 -- Statement ruft alle Listbox-Module der Module aus [V_MODULE_LIST] ab
    JOIN DT406
    ON DT406.DI000969 = DT411.DI000306
    JOIN V_MODULE_LIST
    ON DT406.DI000970 = V_MODULE_LIST.MODULE
    JOIN DT405
    ON DT411.DI000111 = DT405.DI000123
    UNION
    SELECT DISTINCT V_MODULE_LIST.MODULE parent_id,
      DT411.DI027481 mod_id,
      2
    FROM DT411 -- Statement ruft alle Makro-Module der Module aus [V_MODULE_LIST] ab
    JOIN DT406
    ON DT406.DI000969 = DT411.DI000306
    JOIN V_MODULE_LIST
    ON DT406.DI000970 = V_MODULE_LIST.MODULE
    JOIN DT405
    ON DT411.DI027481 = DT405.DI000123
    UNION
    SELECT DISTINCT V_MODULE_LIST.MODULE parent_id,
      DT404.DI028040 mod_id,
      3
    FROM DT404 -- Statement ruft alle Untermodule der Module aus [V_MODULE_LIST] ab
    JOIN V_MODULE_LIST
    ON DT404.DI028100 = V_MODULE_LIST.MODULE
    JOIN DT405
    ON DT404.DI028040 = DT405.DI000123
    ) LMU
  UNION
  SELECT MODULE , MODULE , 0 FROM V_MODULE_LIST;
GO
