Pages

Thursday, August 22, 2013

Sql statement to select all available Maximo applications grouped by its module

SELECT
  LPAD(' ', 2*(LEVEL-1)) ||
  CASE WHEN ELEMENTTYPE = 'MODULE' THEN (SELECT DESCRIPTION FROM MAXIMO.MAXMODULES WHERE MODULE = KEYVALUE)
       WHEN ELEMENTTYPE = 'APP' THEN (SELECT DESCRIPTION FROM MAXIMO.MAXAPPS WHERE APP = KEYVALUE)
       ELSE HEADERDESCRIPTION END DESCRIPTION,
  DECODE(ELEMENTTYPE,'APP',KEYVALUE,NULL) APP
FROM
  ( SELECT
      MODULEAPP,
      POSITION,
      SUBPOSITION,
      ELEMENTTYPE,
      KEYVALUE,
      HEADERDESCRIPTION,
      LEAD(POSITION) OVER (PARTITION BY MODULEAPP, SUBPOSITION ORDER BY POSITION) NEXT_MENU_POS
    FROM
      MAXIMO.MAXMENU
    WHERE MENUTYPE = 'MODULE'
  )
START WITH ELEMENTTYPE = 'MODULE'
CONNECT BY NOCYCLE 
  (MODULEAPP = PRIOR KEYVALUE AND SUBPOSITION = 0 AND PRIOR ELEMENTTYPE = 'MODULE') OR
  (POSITION >= PRIOR POSITION AND POSITION < PRIOR NEXT_MENU_POS AND SUBPOSITION > 0 AND PRIOR ELEMENTTYPE = 'HEADER')
ORDER BY CONNECT_BY_ROOT(POSITION), POSITION, SUBPOSITION; 

No comments:

Post a Comment