Extract all tables and field name

Back to fetch table column

Can you precisely determining every table and column in this SQL statement which is not so much complex with nesting and sub-queries. With us, however, this tedious procedure can become hassle-free one for you.
Here is the result: ( please note that ma_parkey, me_parkey is not real columns although there were appeared in select list )

Tables:
CDS_H_GRUPPE

Fields:
CDS_H_GRUPPE.c_mandant
CDS_H_GRUPPE.funktionscode
CDS_H_GRUPPE.hist_datum
CDS_H_GRUPPE.parkey1
CDS_H_GRUPPE.parkey2
						

SELECT c_mandant, hist_datum, parkey1, parkey2, funktionscode, ma_parkey, me_parkey
     , CASE WHEN EXISTS (SELECT 1
                           FROM CDS_H_GRUPPE  GRP1
                          WHERE GRP1.c_mandant = c_mandant
                            AND GRP1.hist_datum    = ADD_MONTHS(LAST_DAY(TRUNC(SYSDATE)), -1)
                            AND GRP1.funktionscode = 'H'
                            AND GRP1.parkey1       = ma_parkey)
              THEN 1
          ELSE NULL
       END MA_ME
     , CASE WHEN EXISTS (SELECT 1
                           FROM CDS_H_GRUPPE    GRP2
                          WHERE GRP2.c_mandant     = c_mandant
                            AND GRP2.hist_datum    = ADD_MONTHS(LAST_DAY(TRUNC(SYSDATE)), -1)
                            AND GRP2.funktionscode = 'U'
                            AND GRP2.parkey1       = me_parkey)
              THEN 1
          ELSE NULL
       END ME_MA
     , ROW_NUMBER() OVER (PARTITION BY c_mandant, ma_parkey, me_parkey ORDER BY c_mandant, ma_parkey, me_parkey)  ANZ_MA
  FROM (SELECT c_mandant, hist_datum, parkey1, parkey2, funktionscode
             , CASE WHEN funktionscode = 'U'
                      THEN parkey1
                  ELSE parkey2
               END MA_PARKEY
             , CASE WHEN funktionscode = 'U'
                      THEN NULL
                  ELSE parkey1
               END ME_PARKEY
          FROM
               CDS_H_GRUPPE
         WHERE
               funktionscode IN ('U', 'H')
           AND hist_datum    = ADD_MONTHS(LAST_DAY(TRUNC(SYSDATE)), -1)
       )

Detailed explantion how this works: .NET version, Java version

Download this demo: C# demo, Java demo