2022-12-21

[Oracle]How to check account type

SELECT GCC.CODE_COMBINATION_ID CCID,
       SEGMENT1 || '.' || 
       SEGMENT2 || '.' || 
       SEGMENT3 || '.' || 
       SEGMENT4 || '.' ||
       SEGMENT5 || '.' || 
       SEGMENT6 GL_ACCOUNT_SEGMENT,
       GL.DESCRIPTION GL_ACCOUNT_TYPE,
       FFV.FLEX_VALUE,
       GL2.DESCRIPTION FLEX_ACCOUNT_TYPE,
       SUM(NVL(GB.BEGIN_BALANCE_DR, 0) - NVL(GB.BEGIN_BALANCE_CR, 0) +
           NVL(GB.PERIOD_NET_DR, 0) - NVL(GB.PERIOD_NET_CR, 0)) YTD_AMOUNT
  FROM GL_BALANCES          GB,
       GL_CODE_COMBINATIONS GCC,
       GL_LOOKUPS           GL,
       FND_FLEX_VALUES_VL   FFV,
       GL_LOOKUPS           GL2,
       GL_SETS_OF_BOOKS     GSOB
 WHERE 1 = 1
   AND GSOB.SET_OF_BOOKS_ID = GB.LEDGER_ID
   AND GB.TRANSLATED_FLAG IS NULL
   AND GB.CODE_COMBINATION_ID(+) = GCC.CODE_COMBINATION_ID
   AND GCC.ACCOUNT_TYPE = GL.LOOKUP_CODE(+)
   AND GL.LOOKUP_TYPE = 'ACCOUNT TYPE'
   AND GL.ENABLED_FLAG <> 'N'
   AND GCC.CHART_OF_ACCOUNTS_ID = GSOB.CHART_OF_ACCOUNTS_ID
   AND GCC.SEGMENT3 = FFV.FLEX_VALUE(+)
   AND SUBSTR(FFV.COMPILED_VALUE_ATTRIBUTES, 5, 1) = GL2.LOOKUP_CODE(+)
   AND GL2.LOOKUP_TYPE(+) = 'ACCOUNT TYPE'
   AND GL2.ENABLED_FLAG(+) <> 'N'
   AND GB.LEDGER_ID = 1001
   AND GB.PERIOD_YEAR = '2022'
   AND GB.PERIOD_NUM = 12
   AND FFV.FLEX_VALUE_SET_ID(+) = 1009677
--AND GCC.SEGMENT3 = 1101
 HAVING
 SUM(NVL(GB.BEGIN_BALANCE_DR, 0) - NVL(GB.BEGIN_BALANCE_CR, 0) +
           NVL(GB.PERIOD_NET_DR, 0) - NVL(GB.PERIOD_NET_CR, 0)) <> 0
 GROUP BY GCC.CODE_COMBINATION_ID,
          SEGMENT1 || '.' || 
          SEGMENT2 || '.' || 
          SEGMENT3 || '.' || 
          SEGMENT4 || '.' ||
          SEGMENT5 || '.' || 
          SEGMENT6,
          GL.DESCRIPTION,
          FFV.FLEX_VALUE,
          GL2.DESCRIPTION
 ORDER BY GL.DESCRIPTION, FFV.FLEX_VALUE
 

沒有留言:

張貼留言