SQL query concerning an account status

Hello,
I have a table from which I wish to show on which date the account has entered the last serie of days on which it has been with status ST10. In the example the date we are looking for is 16.01.2009. The last time the account has shown such status (ST10) is from 16.01.2009 to 12.02.2009.
Below are the statements for the creation of the table and the insertion of records. Follow the link.
Thank you!
http://dox.bg/files/dw?a=5771159d36
Edited by: harkon on 2011-8-5 5:52

select max(repdate)
from ( select h.*,
nvl(h.repdate-lag(h.repdate) over (order by h.cust_ac_no, h.account_status, h.repdate)-decode(to_char(h.repdate,'DY'),'MON',2,0),100) date_diff
from harkon h
where h.cust_ac_no = '32AC7660106806191 '
and h.account_status = 'ST10 '
where date_diff > 1
or more understandable version:
select max(repdate)
from ( select h.*,
lag(h.repdate) over (order by h.cust_ac_no, h.account_status, h.repdate) prev_date,
decode(to_char(h.repdate,'DY'),
'MON',2,
0) weekend_correction
from harkon h
where h.cust_ac_no = '32AC7660106806191 '
and h.account_status = 'ST10 '
where nvl(repdate-prev_date-weekend_correction,100) > 1
Just to explain what I did:
First, I found out the previous date by using analytic function lag. I also found out the day (is it Monday, Tuesday, Wednesday...), because we have to do the correction if the current day is Monday, since we have 2 days (Saturday and Sunday) for which you do not have records in your table.
After that I found out what is the number of days between previous and current date, also using in account the correction for weekends, so that I can get the difference between Monday and previous Friday as 1 day. If the date has more than 1 day difference in regard to the previous date, it is our candidate for the starting date of the period. As long as the difference of dates is 1 the date is part of the period.
Than I selected maximum of these days, which is the last date when the change you are looking for happened.
Edited by: user13645481 on Aug 5, 2011 6:32 AM

Similar Messages

  • SQL Query to get Account Balance in Oracle Apps

    Hi All,
    I have to use GL Account as a parameter in one of my concurrent programs but before that i need to ensure that the account parameter has no money in it.
    If anyone can help me with a SQL query to find the same, it would be a great help.
    Regards,
    Shruti

    Hi;
    Please follow Subject: Troubleshooting various Issues in Translation of Oracle General Ledger Doc ID: 296379.1 and also etrm site(etrm.oracle.com) for find out more details.
    Regards
    Helios

  • OIM sql Query for getting the status of the task which got failed

    Hi Everyone,
    We have a requirement like we need to get the status of a particular task(say Create User in OID resource - Completed\Rejected status) for the particular user.We are able to get the status of the resource provisioed to the user but not the status of the particular task getting trigerred for the user.can someone put some light on this.We need to get the SQL query for this.
    Thanks in Advance.
    Regards,
    MKN

    Hi
    Use this sample query to get the task status, also check the cooments
    SELECT USR.USR_LOGIN, OSI.SCH_KEY,SCH.SCH_STATUS,STA.STA_BUCKET FROM
    OSI,SCH,STA,MIL,TOS,PKG,OIU,USR,OBJ,OST
    WHERE OSI.MIL_KEY=MIL.MIL_KEY
    AND SCH.SCH_KEY=OSI.SCH_KEY
    AND STA.STA_STATUS=SCH.SCH_STATUS
    AND TOS.PKG_KEY=PKG.PKG_KEY
    AND MIL.TOS_KEY=TOS.TOS_KEY
    AND OIU.USR_KEY=USR.USR_KEY
    AND OIU.OST_KEY=OST.OST_KEY
    AND OST.OBJ_KEY=OBJ.OBJ_KEY
    AND OSI.ORC_KEY=OIU.ORC_KEY
    AND OBJ.OBJ_NAME='AD User'
    AND OST.OST_STATUS = 'Provisioning' -- filter accordinglly
    AND STA.STA_BUCKET = 'Pending' -- filter accordinglly
    AND PKG.PKG_NAME='AD User' -- filter accordinglly
    AND MIL.MIL_NAME='System Validation' ---- filter accordinglly
    Thanks,
    Kuldeep

  • SQL query for "Client Certificate" status

    Hello,
    From the SCCM console, I can check if a given computer does have a valid PKI certificate or not (status from the column "Client Certificate").
    I would to build a collection to identify computers without valid PKI certificate but I cannot find the equivalent.
    Any suggestion ?
    Regards.

    Hi,
    I just found there is a "Https State Flags" attribute in "Configuration Manager Client SSL Configurations" class.
    This could be selected in Criterion Properties.
    Hope this could help you.
    Best Regards,
    Joyce Li
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Possibility to show opening balance of a GL account through SQL query?

    Hi experts,
    Is it possible to run an SQL query in SBO that shows the opening balance
    of a GL account based on a date entered by the user?
    This is similar to how the general ledger shows the opening balance of a GL account based on the posting dates entered.
    Thanks for your ideas.

    Hi Gordon,
    Thanks for that idea.
    I am thinking of the following:
    1. Create a virtual table (#TEST) from a SELECT statement that gets all journal entries for the specified GL account BEFORE the specified posting date.
    2. Perform a SELECT statement that sums the debit and credit from (#TEST).
    This should show the opening balance of the GL account right?
    Regards,
    Eric
    Edited by: eceguerra on May 18, 2011 7:02 AM
    Edited by: eceguerra on May 18, 2011 7:02 AM

  • Help with sql query the status of  A/P Reserve Invoice

    Hi,
    I am trying to write a query which lists all A/P Reserve Invoice info with OPEN status.
    I check the OPCH table and cannot find the rule to tell the status.
    The "DocStatus" field has two values only: 'O' for open and 'C' for closed.
    However, the status of A/P Reserve Invoice are OPEN, CLOSED, DELIVERED, PAID, etc.
    I try to use DocStatus field to filter, but the result does not match what I see in SAP.
    Could you please give me some hints about how to get the data I need? Thank you.
    Best regards,
    Sylvia
    Edited by: csylvia on Jun 23, 2011 5:54 AM

    Hi Darius,
    Thanks for your reply.
    However, I don't know what is the relationship between Purchase order and A/P Reserve Invoice.
    Do you mean using "SELECT T0.DocEntry FROM OPCH T0, OPOR T1 WHERE T0.DocNum = T1.DocNum AND T1.DocStatus = 'O';" to query the A/P Reserve Invoice data with OPEN status?
    But the result is not what I want.
    The result of "*SELECT * FROM OPOR WHERE DocStatus = 'O';*" is also not.
    I'd like to query A/P Reserve Invoice list with OPEN status, and I try the following sql query:
    SELECT DocEntry FROM OPCH WHERE DocStatus = 'O' AND InvntSttus = 'O';
    The result is close to what I need, but it's not exactly correct.
    Moreover, I don't think the sql query conditions is accurate.
    Please give me some advice. Thank you.
    Best regards,
    Sylvia

  • R12 Payables: SQL Query to List Invoices along with their Validation Status

    Hi All,
    I am looking for a SQL query that gives me the list of all AP Invoices and their Validation Status.
    Thanks,
    Anil

    select invoice_id, invoice_num, invoice_amount, invoice_currency_code, approval_status_lookup_code from AP_INVOICES_V ;
    --Prasanna                                                                                                                                                                                                                                                                           

  • Sql query to find all contacts for an account

    I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
    I am also looking for sql query to find all ship to addresses for an account number.
    Thanks.

    Can you also post the query for people who read this post and are also looking for an answer?
    Regards,
    Johan Louwers.

  • SCCM 2007 R2 - SQL query to know the compliance status of the client machines.

    Hi All,
    Can some one share the SQL query that will show the compliance of a "All systems" collection in SCCM 2007 R2 for past six months. I know that it is possible to get the reports from SCCM reporting but would like to run it from database.
    Rgs,

    In SQL queries used in the reports we have prompts and hence I wanted avoid that.
    What wrong with either removing the prompts from the query or hard coding the prompt data?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ

  • Sql Query To Find Out list of users not having a particular resource provisioned

    Hi,
    I know the query for all the resources tagged to user with their account status.
    Can anybody help me with a query to fetch just the user details for the following scenario:
    1)Active users having  having no instance of a particular resource.
    Condition: Exclude Active users having one provisioned instance of the resource and fetch user details having no provisioned account for that resource .
    it is just for report purposes.So format is not of concern.Just need the list of users not having a single provisioned account for a particular resource.

    Hi,
    Please try the below query :
    select distinct usr.usr_login from USR,OIU where USR.USR_KEY not in (select OIU.USR_KEY from OIU)
    and OIU.APP_INSTANCE_KEY= (select APP_INSTANCE_KEY from APP_INSTANCE where APP_INSTANCE_NAME='ADResource');
    Change the app instance name acording to you need.
    -Saurabh

  • Sql query is hung, doesn't comes back

    Hello Every one,
    Two node Rac on Linux 5 64-bit, 11.2.0.1.0
    In our data ware housing environment, i have a sql query which doesn't comes back at all, when i run, it is just hung for a long time with no output. I did following basic testing
    1. All the indexes are valid and stats are up to date(count(*) matches num rows)
    2. There is a union clause in the query, i divided the query in two parts - the first part prior to union and second part after union, then i ran those two parts separately - the first part comes back quickly with no rows selected but the second part has a main problem(its just hung).
    Please note that one table in the query has a partitioned table. following is the query and the tables involved in it.
    Please let me know if you need any further information, it will be of great help if i get through this. Thanks in advance.
    OWNER                          TABLE_NAME                     STATUS   LAST_ANAL   NUM_ROWS
    MAINTENANCE_DM                 D_VEHICLE                      VALID    21-NOV-12     752590
    PTL_HOLD                       R_COMP_CODES                   VALID    21-NOV-12        108
    PTL_HOLD                       USER_GEO                       VALID    20-DEC-12        300
    PTL_EDW                        D_CUSTOMER                     VALID    20-DEC-12     219498
    PTL_EDW                        D_LOCN                         VALID    20-DEC-12      19456
    PTL_EDW                        D_VEHICLE                      VALID    20-DEC-12    3973271
    PTL_EDW                        F_VEH_LOCN                     VALID    20-DEC-12    3131138
    PTL_EDW                        F_RO_DETL                      VALID    21-NOV-12   29234052
    8 rows selected.
    SELECT
      '../../opendoc/',
      '&hideSave=true&hideEdit=true&hideRefresh=true&hideUserPromptInput=true',
      'Data As Of:',
      'Run Date:',
      ptl_hold.get_stgextr_time('FACT_FPNA_RO'),
      'RO Date',
      PTL_EDW.F_RO_DETL.RO_TYP,
      PTL_EDW.D_CUSTOMER.CUST_NUM,
      (PTL_EDW.D_CUSTOMER.CUST_NUM )||' - '||( PTL_EDW.D_CUSTOMER.CUST_PRIME_NM),
      PTL_EDW.D_CUSTOMER.BILL_GRP,
      CASE WHEN PTL_EDW.D_LOCN.CORP_CD='HPTL' THEN 'US' ELSE CASE WHEN  PTL_EDW.D_LOCN.CORP_CD='2000' THEN 'CANADA' ELSE 'UNKNOWN' END END,
      PTL_EDW.D_LOCN.REGN_NUM,
      PTL_EDW.D_LOCN.REGN_NUM ||' - '||PTL_EDW.D_LOCN.REGN_NM,
      PTL_EDW.D_LOCN.AREA_NUM,
      PTL_EDW.D_LOCN.AREA_NUM||' - '||PTL_EDW.D_LOCN.AREA_NM,
      PTL_EDW.D_LOCN.RDIST_NUM,
      PTL_EDW.D_LOCN.RDIST_NUM||' - '||PTL_EDW.D_LOCN.RDIST_NM,
      PTL_EDW.D_LOCN.DIST_NUM,
      PTL_EDW.D_LOCN.DIST_NUM||' - '||PTL_EDW.D_LOCN.DIST_NM,
      CASE WHEN TRIM(PTL_EDW.D_VEHICLE.VEH_CAP_STAT) IN ('ACTIVE','ACCRUED') THEN 'Active' ELSE 'Inactive' END,
      DECODE(PTL_EDW.D_VEHICLE.CONTR_GRP, 'X' ,'NON-CONTRACT',PTL_EDW.D_VEHICLE.VEH_CAT),
      PTL_EDW.D_VEHICLE.VEH_UNIT_TYP,
      PTL_EDW.D_VEHICLE.VEH_MODL_YR,
      PTL_EDW.D_VEHICLE.VEH_MAKE,
      PTL_EDW.D_VEHICLE.VEH_MODEL,
      CASE WHEN ( PTL_HOLD.R_COMP_CODES.COMP_CD ) IN ('057','061') THEN 'Accident/Incident' ELSE 'Non-Accident/Incident' END,
      PTL_HOLD.R_COMP_CODES.COMP_CD,
      PTL_HOLD.R_COMP_CODES.COMP_DESC,
      PTL_HOLD.R_COMP_CODES.COMP_CD||' - '||PTL_HOLD.R_COMP_CODES.COMP_DESC,
      PTL_EDW.D_VEHICLE.UNIT_NUM,
      PTL_EDW_D_RO_LOCN.DIST_NUM || PTL_EDW_D_RO_LOCN.DIST_SUFX ||  PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM,
      PTL_EDW_D_RO_LOCN.DIST_NUM || PTL_EDW_D_RO_LOCN.DIST_SUFX || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM || PTL_EDW.F_RO_DETL.RO_SEQ_NUM
      PTL_EDW.F_RO_DETL.RO_SRC,
      PTL_EDW.F_RO_DETL.TOTAL_LABOR_HRS,
      PTL_EDW.F_RO_DETL.TOTAL_LABOR_COST,
      PTL_EDW.F_RO_DETL.OUT_COST,
      PTL_EDW.F_RO_DETL.PARTS_COST,
      PTL_EDW.F_RO_DETL.RO_COST,
      TO_CHAR(PTL_EDW_D_RO_LOCN.LOCN_KEY),
      PTL_EDW.F_RO_DETL.RO_NUM,
      PTL_EDW.F_RO_DETL.RO_SEQ_NUM,
      PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    FROM
      PTL_EDW.F_RO_DETL,
      PTL_EDW.D_CUSTOMER,
      PTL_EDW.D_LOCN,
      PTL_EDW.D_VEHICLE,
      PTL_HOLD.R_COMP_CODES,
      PTL_EDW.D_LOCN  PTL_EDW_D_RO_LOCN,
      PTL_EDW.D_LOCN  PTL_EDW_D_CHRG_LOCN,
      PTL_EDW.D_TIME,
      PTL_EDW.D_LOCN  CURRENT_VEH_LOCN,
      PTL_EDW.F_VEH_LOCN,
      PTL_EDW.D_VEHICLE  CURRENT_VEH
    WHERE
      ( PTL_EDW.F_RO_DETL.CUST_KEY=PTL_EDW.D_CUSTOMER.CUST_KEY  )
      AND  ( PTL_EDW.F_RO_DETL.LOCN_KEY=PTL_EDW.D_LOCN.LOCN_KEY  )
      AND  ( PTL_EDW.D_TIME.TIME_KEY=PTL_EDW.F_RO_DETL.RO_TIME_KEY  )
      AND  ( PTL_EDW.D_VEHICLE.VEH_KEY=PTL_EDW.F_RO_DETL.VEH_KEY  )
      AND  ( PTL_EDW_D_RO_LOCN.LOCN_KEY=PTL_EDW.F_RO_DETL.RO_LOCN_KEY  )
      AND  ( PTL_EDW.F_RO_DETL.CHRG_LOCN_KEY=PTL_EDW_D_CHRG_LOCN.LOCN_KEY  )
      AND  ( CURRENT_VEH_LOCN.LOCN_KEY=PTL_EDW.F_VEH_LOCN.LOCN_KEY  )
      AND  ( CURRENT_VEH.SCD_FLG='A'  )
      AND  ( CURRENT_VEH.CONTR_GRP='P'  )
      AND  ( CURRENT_VEH.CORP_CD=PTL_EDW.D_VEHICLE.CORP_CD and CURRENT_VEH.UNIT_NUM=PTL_EDW.D_VEHICLE.UNIT_NUM  )
      AND  ( CURRENT_VEH.VEH_KEY=PTL_EDW.F_VEH_LOCN.VEH_KEY  )
      AND  ( PTL_HOLD.R_COMP_CODES.COMP_CD=PTL_EDW.F_RO_DETL.COMP_CD  )
      AND 
       ( 'Accounting Month' = 'RO Date'  )
       AND
       ( '2500' = 'NO-MIN'
    OR    EXISTS(SELECT RO_TOTAL_COST.RO_LOCN_KEY, RO_TOTAL_COST.ORIGINAL_RO_NUM 
    FROM      PTL_EDW.F_RO_DETL RO_TOTAL_COST,
        PTL_EDW.D_TIME DTIME
    WHERE
        ('I' = 'I'
        OR ('I' = 'E'
            AND RO_TOTAL_COST.RO_TYP  <>  'W'))
        AND RO_TOTAL_COST.RO_LOCN_KEY = PTL_EDW.F_RO_DETL.RO_LOCN_KEY
        AND RO_TOTAL_COST.ORIGINAL_RO_NUM = PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
        AND RO_TOTAL_COST.RO_TIME_KEY = DTIME.TIME_KEY
        AND DTIME.CALENDAR_DT BETWEEN to_date('2011-JAN-01') AND to_date('2012-SEP-24')
    GROUP BY
        RO_TOTAL_COST.RO_LOCN_KEY,
        RO_TOTAL_COST.ORIGINAL_RO_NUM
    HAVING
    Sum(RO_TOTAL_COST.RO_COST) >= TO_NUMBER(translate('2500','NO-MIN',' ')))
       AND
       PTL_EDW_D_CHRG_LOCN.DIST_NUM_SUFX  IN  ('014810')
       AND
       ( PTL_EDW.D_TIME.CALENDAR_DT  BETWEEN  to_date('2011-JAN-01') AND to_date('2012-SEP-24')  )
       AND
       ( 'I'  = 'I'
      OR
      ( 'I' = 'E'
         And ( ( PTL_EDW.F_RO_DETL.RO_TYP ) <> 'W'
       AND
       ( EXISTS(SELECT *  FROM PTL_HOLD.USER_GEO WHERE USERID='600125729' AND PTL_HOLD.USER_GEO.GEO IN (CURRENT_VEH_LOCN.CORP_CD, CURRENT_VEH_LOCN.REGN_NUM, CURRENT_VEH_LOCN.AREA_NUM, CURRENT_VEH_LOCN.RDIST_NUM, CURRENT_VEH_LOCN.DIST_NUM))  )
    UNION 
    SELECT
      '../../opendoc/',
      '&hideSave=true&hideEdit=true&hideRefresh=true&hideUserPromptInput=true',
      'Data As Of:',
      'Run Date:',
      ptl_hold.get_stgextr_time('FACT_FPNA_RO'),
      'Accounting Month',
      PTL_EDW.F_RO_DETL.RO_TYP,
      PTL_EDW.D_CUSTOMER.CUST_NUM,
      (PTL_EDW.D_CUSTOMER.CUST_NUM )||' - '||( PTL_EDW.D_CUSTOMER.CUST_PRIME_NM),
      PTL_EDW.D_CUSTOMER.BILL_GRP,
      CASE WHEN PTL_EDW.D_LOCN.CORP_CD='HPTL' THEN 'US' ELSE CASE WHEN  PTL_EDW.D_LOCN.CORP_CD='2000' THEN 'CANADA' ELSE 'UNKNOWN' END END,
      PTL_EDW.D_LOCN.REGN_NUM,
      PTL_EDW.D_LOCN.REGN_NUM ||' - '||PTL_EDW.D_LOCN.REGN_NM,
      PTL_EDW.D_LOCN.AREA_NUM,
      PTL_EDW.D_LOCN.AREA_NUM||' - '||PTL_EDW.D_LOCN.AREA_NM,
      PTL_EDW.D_LOCN.RDIST_NUM,
      PTL_EDW.D_LOCN.RDIST_NUM||' - '||PTL_EDW.D_LOCN.RDIST_NM,
      PTL_EDW.D_LOCN.DIST_NUM,
      PTL_EDW.D_LOCN.DIST_NUM||' - '||PTL_EDW.D_LOCN.DIST_NM,
      CASE WHEN TRIM(PTL_EDW.D_VEHICLE.VEH_CAP_STAT) IN ('ACTIVE','ACCRUED') THEN 'Active' ELSE 'Inactive' END,
      DECODE(PTL_EDW.D_VEHICLE.CONTR_GRP, 'X' ,'NON-CONTRACT',PTL_EDW.D_VEHICLE.VEH_CAT),
      PTL_EDW.D_VEHICLE.VEH_UNIT_TYP,
      PTL_EDW.D_VEHICLE.VEH_MODL_YR,
      PTL_EDW.D_VEHICLE.VEH_MAKE,
      PTL_EDW.D_VEHICLE.VEH_MODEL,
      CASE WHEN ( PTL_HOLD.R_COMP_CODES.COMP_CD ) IN ('057','061') THEN 'Accident/Incident' ELSE 'Non-Accident/Incident' END,
      PTL_HOLD.R_COMP_CODES.COMP_CD,
      PTL_HOLD.R_COMP_CODES.COMP_DESC,
      PTL_HOLD.R_COMP_CODES.COMP_CD||' - '||PTL_HOLD.R_COMP_CODES.COMP_DESC,
      PTL_EDW.D_VEHICLE.UNIT_NUM,
      PTL_EDW_D_RO_LOCN.DIST_NUM || PTL_EDW_D_RO_LOCN.DIST_SUFX ||  PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM,
      PTL_EDW_D_RO_LOCN.DIST_NUM || PTL_EDW_D_RO_LOCN.DIST_SUFX || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM || PTL_EDW.F_RO_DETL.RO_SEQ_NUM
      PTL_EDW.F_RO_DETL.RO_SRC,
      PTL_EDW.F_RO_DETL.TOTAL_LABOR_HRS,
      PTL_EDW.F_RO_DETL.TOTAL_LABOR_COST,
      PTL_EDW.F_RO_DETL.OUT_COST,
      PTL_EDW.F_RO_DETL.PARTS_COST,
      PTL_EDW.F_RO_DETL.RO_COST,
      TO_CHAR(PTL_EDW_D_RO_LOCN.LOCN_KEY),
      PTL_EDW.F_RO_DETL.RO_NUM,
      PTL_EDW.F_RO_DETL.RO_SEQ_NUM,
      PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    FROM
      PTL_EDW.F_RO_DETL,
      PTL_EDW.D_CUSTOMER,
      PTL_EDW.D_LOCN,
      PTL_EDW.D_VEHICLE,
      PTL_HOLD.R_COMP_CODES,
      PTL_EDW.D_LOCN  PTL_EDW_D_RO_LOCN,
      PTL_EDW.D_LOCN  PTL_EDW_D_CHRG_LOCN,
      PTL_EDW.D_LOCN  CURRENT_VEH_LOCN,
      PTL_EDW.F_VEH_LOCN,
      PTL_EDW.D_VEHICLE  CURRENT_VEH
    WHERE
      ( PTL_EDW.F_RO_DETL.CUST_KEY=PTL_EDW.D_CUSTOMER.CUST_KEY  )
      AND  ( PTL_EDW.F_RO_DETL.LOCN_KEY=PTL_EDW.D_LOCN.LOCN_KEY  )
      AND  ( PTL_EDW.D_VEHICLE.VEH_KEY=PTL_EDW.F_RO_DETL.VEH_KEY  )
      AND  ( PTL_EDW_D_RO_LOCN.LOCN_KEY=PTL_EDW.F_RO_DETL.RO_LOCN_KEY  )
      AND  ( PTL_EDW.F_RO_DETL.CHRG_LOCN_KEY=PTL_EDW_D_CHRG_LOCN.LOCN_KEY  )
      AND  ( CURRENT_VEH_LOCN.LOCN_KEY=PTL_EDW.F_VEH_LOCN.LOCN_KEY  )
      AND  ( CURRENT_VEH.SCD_FLG='A'  )
      AND  ( CURRENT_VEH.CONTR_GRP='P'  )
      AND  ( CURRENT_VEH.CORP_CD=PTL_EDW.D_VEHICLE.CORP_CD and CURRENT_VEH.UNIT_NUM=PTL_EDW.D_VEHICLE.UNIT_NUM  )
      AND  ( CURRENT_VEH.VEH_KEY=PTL_EDW.F_VEH_LOCN.VEH_KEY  )
      AND  ( PTL_HOLD.R_COMP_CODES.COMP_CD=PTL_EDW.F_RO_DETL.COMP_CD  )
      AND 
       ( 'Accounting Month' = 'Accounting Month'  )
       AND
       ( '2500' = 'NO-MIN'
    OR           EXISTS(SELECT RO_TOTAL_COST.RO_LOCN_KEY, RO_TOTAL_COST.ORIGINAL_RO_NUM
    FROM      PTL_EDW.F_RO_DETL RO_TOTAL_COST
    WHERE
        ('I' = 'I'
        OR ('I' = 'E'
            AND RO_TOTAL_COST.RO_TYP  <>  'W'))
        AND RO_TOTAL_COST.RO_LOCN_KEY = PTL_EDW.F_RO_DETL.RO_LOCN_KEY
        AND RO_TOTAL_COST.ORIGINAL_RO_NUM = PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
        AND RO_TOTAL_COST.PARTITION_KEY BETWEEN 
           to_number(to_char(to_date('2011-JAN-01','YYYY-MON-DD'),'yyyymm')) 
           AND  to_number(to_char(to_date('2012-SEP-24','YYYY-MON-DD'),'yyyymm'))
    GROUP BY
        RO_TOTAL_COST.RO_LOCN_KEY,
        RO_TOTAL_COST.ORIGINAL_RO_NUM
    HAVING
    Sum(RO_TOTAL_COST.RO_COST) >= TO_NUMBER(translate('2500','NO-MIN',' ')))  )
       AND
       PTL_EDW_D_CHRG_LOCN.DIST_NUM_SUFX  IN  ('014810')
       AND
       ( (PTL_EDW.F_RO_DETL.PARTITION_KEY BETWEEN 
           to_number(to_char(to_date('2011-JAN-01','YYYY-MON-DD'),'yyyymm')) 
           AND  to_number(to_char(to_date('2012-SEP-24','YYYY-MON-DD'),'yyyymm'))
       AND
       ( 'I'  = 'I'
      OR
      ( 'I' = 'E'
         And ( ( PTL_EDW.F_RO_DETL.RO_TYP ) <> 'W'
       AND
       ( EXISTS(SELECT *  FROM PTL_HOLD.USER_GEO WHERE USERID='600125729' AND PTL_HOLD.USER_GEO.GEO IN (CURRENT_VEH_LOCN.CORP_CD, CURRENT_VEH_LOCN.REGN_NUM, CURRENT_VEH_LOCN.AREA_NUM, CURRENT_VEH_LOCN.RDIST_NUM, CURRENT_VEH_LOCN.DIST_NUM))  )
    );Thank you.

    For your own sanity, you should learn to format your code. For the sake of the forum members, you should preserve the formatting by using the \ tags. 
    I've done that for you here, and some other questions popped right out.  Look for my embedded comments near the bottomSELECT
    '../../opendoc/',
    '&hideSave=true&hideEdit=true&hideRefresh=true&hideUserPromptInput=true'
    'Data As Of:' ,
    'Run Date:' ,
    ptl_hold.get_stgextr_time('FACT_FPNA_RO'),
    'RO Date' ,
    PTL_EDW.F_RO_DETL.RO_TYP ,
    PTL_EDW.D_CUSTOMER.CUST_NUM ,
    (PTL_EDW.D_CUSTOMER.CUST_NUM )
    ||' - '
    ||( PTL_EDW.D_CUSTOMER.CUST_PRIME_NM),
    PTL_EDW.D_CUSTOMER.BILL_GRP ,
    CASE
    WHEN PTL_EDW.D_LOCN.CORP_CD='HPTL'
    THEN 'US'
    ELSE
    CASE
    WHEN PTL_EDW.D_LOCN.CORP_CD='2000'
    THEN 'CANADA'
    ELSE 'UNKNOWN'
    END
    END ,
    PTL_EDW.D_LOCN.REGN_NUM,
    PTL_EDW.D_LOCN.REGN_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.REGN_NM,
    PTL_EDW.D_LOCN.AREA_NUM ,
    PTL_EDW.D_LOCN.AREA_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.AREA_NM,
    PTL_EDW.D_LOCN.RDIST_NUM,
    PTL_EDW.D_LOCN.RDIST_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.RDIST_NM,
    PTL_EDW.D_LOCN.DIST_NUM ,
    PTL_EDW.D_LOCN.DIST_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.DIST_NM,
    CASE
    WHEN TRIM(PTL_EDW.D_VEHICLE.VEH_CAP_STAT) IN
    ('ACTIVE','ACCRUED')
    THEN 'Active'
    ELSE 'Inactive'
    END,
    DECODE(PTL_EDW.D_VEHICLE.CONTR_GRP, 'X' ,
    'NON-CONTRACT',PTL_EDW.D_VEHICLE.VEH_CAT),
    PTL_EDW.D_VEHICLE.VEH_UNIT_TYP ,
    PTL_EDW.D_VEHICLE.VEH_MODL_YR ,
    PTL_EDW.D_VEHICLE.VEH_MAKE ,
    PTL_EDW.D_VEHICLE.VEH_MODEL ,
    CASE
    WHEN
    PTL_HOLD.R_COMP_CODES.COMP_CD
    IN ('057','061')
    THEN 'Accident/Incident'
    ELSE 'Non-Accident/Incident'
    END ,
    PTL_HOLD.R_COMP_CODES.COMP_CD ,
    PTL_HOLD.R_COMP_CODES.COMP_DESC,
    PTL_HOLD.R_COMP_CODES.COMP_CD
    ||' - '
    ||PTL_HOLD.R_COMP_CODES.COMP_DESC,
    PTL_EDW.D_VEHICLE.UNIT_NUM ,
    PTL_EDW_D_RO_LOCN.DIST_NUM
    || PTL_EDW_D_RO_LOCN.DIST_SUFX
    || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM,
    PTL_EDW_D_RO_LOCN.DIST_NUM
    || PTL_EDW_D_RO_LOCN.DIST_SUFX
    || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    || PTL_EDW.F_RO_DETL.RO_SEQ_NUM ,
    PTL_EDW.F_RO_DETL.RO_SRC ,
    PTL_EDW.F_RO_DETL.TOTAL_LABOR_HRS ,
    PTL_EDW.F_RO_DETL.TOTAL_LABOR_COST ,
    PTL_EDW.F_RO_DETL.OUT_COST ,
    PTL_EDW.F_RO_DETL.PARTS_COST ,
    PTL_EDW.F_RO_DETL.RO_COST ,
    TO_CHAR(PTL_EDW_D_RO_LOCN.LOCN_KEY),
    PTL_EDW.F_RO_DETL.RO_NUM ,
    PTL_EDW.F_RO_DETL.RO_SEQ_NUM ,
    PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    FROM
    PTL_EDW.F_RO_DETL ,
    PTL_EDW.D_CUSTOMER ,
    PTL_EDW.D_LOCN ,
    PTL_EDW.D_VEHICLE ,
    PTL_HOLD.R_COMP_CODES ,
    PTL_EDW.D_LOCN PTL_EDW_D_RO_LOCN ,
    PTL_EDW.D_LOCN PTL_EDW_D_CHRG_LOCN,
    PTL_EDW.D_TIME ,
    PTL_EDW.D_LOCN CURRENT_VEH_LOCN ,
    PTL_EDW.F_VEH_LOCN ,
    PTL_EDW.D_VEHICLE CURRENT_VEH
    WHERE
    PTL_EDW.F_RO_DETL.CUST_KEY =
    PTL_EDW.D_CUSTOMER.CUST_KEY
    AND
    PTL_EDW.F_RO_DETL.LOCN_KEY =
    PTL_EDW.D_LOCN.LOCN_KEY
    AND
    PTL_EDW.D_TIME.TIME_KEY =
    PTL_EDW.F_RO_DETL.RO_TIME_KEY
    AND
    PTL_EDW.D_VEHICLE.VEH_KEY =
    PTL_EDW.F_RO_DETL.VEH_KEY
    AND
    PTL_EDW_D_RO_LOCN.LOCN_KEY =
    PTL_EDW.F_RO_DETL.RO_LOCN_KEY
    AND
    PTL_EDW.F_RO_DETL.CHRG_LOCN_KEY=
    PTL_EDW_D_CHRG_LOCN.LOCN_KEY
    AND
    CURRENT_VEH_LOCN.LOCN_KEY =
    PTL_EDW.F_VEH_LOCN.LOCN_KEY
    AND
    CURRENT_VEH.SCD_FLG ='A'
    AND
    CURRENT_VEH.CONTR_GRP ='P'
    AND
    CURRENT_VEH.CORP_CD =
    PTL_EDW.D_VEHICLE.CORP_CD
    AND CURRENT_VEH.UNIT_NUM =
    PTL_EDW.D_VEHICLE.UNIT_NUM
    AND
    CURRENT_VEH.VEH_KEY =
    PTL_EDW.F_VEH_LOCN.VEH_KEY
    AND
    PTL_HOLD.R_COMP_CODES.COMP_CD =
    PTL_EDW.F_RO_DETL.COMP_CD
    AND
    'Accounting Month' = 'RO Date'
    AND
    '2500' = 'NO-MIN'
    OR EXISTS
    SELECT
    RO_TOTAL_COST.RO_LOCN_KEY,
    RO_TOTAL_COST.ORIGINAL_RO_NUM
    FROM
    PTL_EDW.F_RO_DETL RO_TOTAL_COST,
    PTL_EDW.D_TIME DTIME
    WHERE
    'I' = 'I'
    OR
    'I' = 'E'
    AND RO_TOTAL_COST.RO_TYP 'W'
    AND RO_TOTAL_COST.RO_LOCN_KEY =
    PTL_EDW.F_RO_DETL.RO_LOCN_KEY
    AND RO_TOTAL_COST.ORIGINAL_RO_NUM =
    PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    AND RO_TOTAL_COST.RO_TIME_KEY =
    DTIME.TIME_KEY
    AND DTIME.CALENDAR_DT BETWEEN to_date(
    '2011-JAN-01') AND to_date(
    '2012-SEP-24')
    GROUP BY
    RO_TOTAL_COST.RO_LOCN_KEY,
    RO_TOTAL_COST.ORIGINAL_RO_NUM
    HAVING
    SUM(RO_TOTAL_COST.RO_COST) >= TO_NUMBER
    (TRANSLATE('2500','NO-MIN',' '))
    AND PTL_EDW_D_CHRG_LOCN.DIST_NUM_SUFX IN (
    '014810')
    AND
    PTL_EDW.D_TIME.CALENDAR_DT BETWEEN to_date(
    '2011-JAN-01') AND to_date('2012-SEP-24')
    AND
    'I' = 'I'
    OR
    'I' = 'E'
    AND
    PTL_EDW.F_RO_DETL.RO_TYP
    'W'
    AND
    EXISTS
    SELECT
    FROM
    PTL_HOLD.USER_GEO
    WHERE
    USERID ='600125729'
    AND PTL_HOLD.USER_GEO.GEO IN (
    CURRENT_VEH_LOCN.CORP_CD,
    CURRENT_VEH_LOCN.REGN_NUM,
    CURRENT_VEH_LOCN.AREA_NUM,
    CURRENT_VEH_LOCN.RDIST_NUM,
    CURRENT_VEH_LOCN.DIST_NUM)
    UNION
    SELECT
    '../../opendoc/',
    '&hideSave=true&hideEdit=true&hideRefresh=true&hideUserPromptInput=true'
    'Data As Of:' ,
    'Run Date:' ,
    ptl_hold.get_stgextr_time('FACT_FPNA_RO'),
    'Accounting Month' ,
    PTL_EDW.F_RO_DETL.RO_TYP ,
    PTL_EDW.D_CUSTOMER.CUST_NUM ,
    (PTL_EDW.D_CUSTOMER.CUST_NUM )
    ||' - '
    ||( PTL_EDW.D_CUSTOMER.CUST_PRIME_NM),
    PTL_EDW.D_CUSTOMER.BILL_GRP ,
    CASE
    WHEN PTL_EDW.D_LOCN.CORP_CD='HPTL'
    THEN 'US'
    ELSE
    CASE
    WHEN PTL_EDW.D_LOCN.CORP_CD='2000'
    THEN 'CANADA'
    ELSE 'UNKNOWN'
    END
    END ,
    PTL_EDW.D_LOCN.REGN_NUM,
    PTL_EDW.D_LOCN.REGN_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.REGN_NM,
    PTL_EDW.D_LOCN.AREA_NUM ,
    PTL_EDW.D_LOCN.AREA_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.AREA_NM,
    PTL_EDW.D_LOCN.RDIST_NUM,
    PTL_EDW.D_LOCN.RDIST_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.RDIST_NM,
    PTL_EDW.D_LOCN.DIST_NUM ,
    PTL_EDW.D_LOCN.DIST_NUM
    ||' - '
    ||PTL_EDW.D_LOCN.DIST_NM,
    CASE
    WHEN TRIM(PTL_EDW.D_VEHICLE.VEH_CAP_STAT) IN
    ('ACTIVE','ACCRUED')
    THEN 'Active'
    ELSE 'Inactive'
    END,
    DECODE(PTL_EDW.D_VEHICLE.CONTR_GRP, 'X' ,
    'NON-CONTRACT',PTL_EDW.D_VEHICLE.VEH_CAT),
    PTL_EDW.D_VEHICLE.VEH_UNIT_TYP ,
    PTL_EDW.D_VEHICLE.VEH_MODL_YR ,
    PTL_EDW.D_VEHICLE.VEH_MAKE ,
    PTL_EDW.D_VEHICLE.VEH_MODEL ,
    CASE
    WHEN
    PTL_HOLD.R_COMP_CODES.COMP_CD
    IN ('057','061')
    THEN 'Accident/Incident'
    ELSE 'Non-Accident/Incident'
    END ,
    PTL_HOLD.R_COMP_CODES.COMP_CD ,
    PTL_HOLD.R_COMP_CODES.COMP_DESC,
    PTL_HOLD.R_COMP_CODES.COMP_CD
    ||' - '
    ||PTL_HOLD.R_COMP_CODES.COMP_DESC,
    PTL_EDW.D_VEHICLE.UNIT_NUM ,
    PTL_EDW_D_RO_LOCN.DIST_NUM
    || PTL_EDW_D_RO_LOCN.DIST_SUFX
    || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM,
    PTL_EDW_D_RO_LOCN.DIST_NUM
    || PTL_EDW_D_RO_LOCN.DIST_SUFX
    || PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    || PTL_EDW.F_RO_DETL.RO_SEQ_NUM ,
    PTL_EDW.F_RO_DETL.RO_SRC ,
    PTL_EDW.F_RO_DETL.TOTAL_LABOR_HRS ,
    PTL_EDW.F_RO_DETL.TOTAL_LABOR_COST ,
    PTL_EDW.F_RO_DETL.OUT_COST ,
    PTL_EDW.F_RO_DETL.PARTS_COST ,
    PTL_EDW.F_RO_DETL.RO_COST ,
    TO_CHAR(PTL_EDW_D_RO_LOCN.LOCN_KEY),
    PTL_EDW.F_RO_DETL.RO_NUM ,
    PTL_EDW.F_RO_DETL.RO_SEQ_NUM ,
    PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    FROM
    PTL_EDW.F_RO_DETL ,
    PTL_EDW.D_CUSTOMER ,
    PTL_EDW.D_LOCN ,
    PTL_EDW.D_VEHICLE ,
    PTL_HOLD.R_COMP_CODES ,
    PTL_EDW.D_LOCN PTL_EDW_D_RO_LOCN ,
    PTL_EDW.D_LOCN PTL_EDW_D_CHRG_LOCN,
    PTL_EDW.D_LOCN CURRENT_VEH_LOCN ,
    PTL_EDW.F_VEH_LOCN ,
    PTL_EDW.D_VEHICLE CURRENT_VEH
    WHERE
    PTL_EDW.F_RO_DETL.CUST_KEY =
    PTL_EDW.D_CUSTOMER.CUST_KEY
    AND
    PTL_EDW.F_RO_DETL.LOCN_KEY =
    PTL_EDW.D_LOCN.LOCN_KEY
    AND
    PTL_EDW.D_VEHICLE.VEH_KEY =
    PTL_EDW.F_RO_DETL.VEH_KEY
    AND
    PTL_EDW_D_RO_LOCN.LOCN_KEY =
    PTL_EDW.F_RO_DETL.RO_LOCN_KEY
    AND
    PTL_EDW.F_RO_DETL.CHRG_LOCN_KEY=
    PTL_EDW_D_CHRG_LOCN.LOCN_KEY
    AND
    CURRENT_VEH_LOCN.LOCN_KEY =
    PTL_EDW.F_VEH_LOCN.LOCN_KEY
    AND
    CURRENT_VEH.SCD_FLG ='A'
    AND
    CURRENT_VEH.CONTR_GRP ='P'
    AND
    CURRENT_VEH.CORP_CD =
    PTL_EDW.D_VEHICLE.CORP_CD
    AND CURRENT_VEH.UNIT_NUM =
    PTL_EDW.D_VEHICLE.UNIT_NUM
    AND
    CURRENT_VEH.VEH_KEY =
    PTL_EDW.F_VEH_LOCN.VEH_KEY
    AND
    PTL_HOLD.R_COMP_CODES.COMP_CD =
    PTL_EDW.F_RO_DETL.COMP_CD
    AND
    'Accounting Month' = 'Accounting Month'
    AND
    '2500' = 'NO-MIN'
    OR EXISTS
    SELECT
    RO_TOTAL_COST.RO_LOCN_KEY,
    RO_TOTAL_COST.ORIGINAL_RO_NUM
    FROM
    PTL_EDW.F_RO_DETL RO_TOTAL_COST
    WHERE
    'I' = 'I'
    /* what's the point? A literal always equals itself. /*
    OR
    'I' = 'E'
    /* again, what's the point? This will never be true */
    AND RO_TOTAL_COST.RO_TYP 'W'
    AND RO_TOTAL_COST.RO_LOCN_KEY =
    PTL_EDW.F_RO_DETL.RO_LOCN_KEY
    AND RO_TOTAL_COST.ORIGINAL_RO_NUM =
    PTL_EDW.F_RO_DETL.ORIGINAL_RO_NUM
    AND RO_TOTAL_COST.PARTITION_KEY BETWEEN
    to_number(TO_CHAR(to_date('2011-JAN-01','YYYY-MON-DD'),'yyyymm')) AND
    to_number(TO_CHAR(to_date('2012-SEP-24','YYYY-MON-DD'),'yyyymm'))
    /* what is the data type of PARTITION_KEY? This manipulation strongly suggests that it should be DATE and isn't.
    GROUP BY
    RO_TOTAL_COST.RO_LOCN_KEY,
    RO_TOTAL_COST.ORIGINAL_RO_NUM
    HAVING
    SUM(RO_TOTAL_COST.RO_COST) >= TO_NUMBER(TRANSLATE('2500','NO-MIN',' '))
    AND PTL_EDW_D_CHRG_LOCN.DIST_NUM_SUFX IN (
    '014810')
    AND
    PTL_EDW.F_RO_DETL.PARTITION_KEY BETWEEN
    to_number(TO_CHAR(to_date('2011-JAN-01',
    'YYYY-MON-DD'),'yyyymm')) AND to_number(
    TO_CHAR(to_date('2012-SEP-24',
    'YYYY-MON-DD'),'yyyymm'))
    AND
    'I' = 'I'
    OR
    'I' = 'E'
    AND
    PTL_EDW.F_RO_DETL.RO_TYP
    'W'
    AND
    EXISTS
    SELECT
    FROM
    PTL_HOLD.USER_GEO
    WHERE
    USERID ='600125729'
    AND PTL_HOLD.USER_GEO.GEO IN (
    CURRENT_VEH_LOCN.CORP_CD,
    CURRENT_VEH_LOCN.REGN_NUM,
    CURRENT_VEH_LOCN.AREA_NUM,
    CURRENT_VEH_LOCN.RDIST_NUM,
    CURRENT_VEH_LOCN.DIST_NUM)

  • Customer details SQL Query

    Hi All,
    I need an sql query which shows customer details as follows: Customer party id, customer name, customer account id, customer account number, party site number, address1, address2, city, country, customer contact phone number. I developed the below query but it shows lot of repeated records with incorrect party site number.
    Please assist.
    SELECT hp.party_id,hp.party_name customer_name,hcp.phone_number,cust.account_number, hps.party_site_number, hl.ADDRESS1, hl.address2, hl.address3, hl.city,hl.country--, hp.person_first_name first_name, hp.person_last_name last_name
    FROM
    hz_parties hp,
    hz_relationships hr,
    hz_parties h_contact ,
    hz_contact_points hcp,
    hz_cust_accounts cust,
    hz_party_sites hps,
    hz_locations hl
    where hr.subject_id = h_contact.PARTY_ID
    and hr.object_id = hp.party_id
    AND hcp.owner_table_id(+) = hr.party_id
    AND cust.party_id = hp.party_id
    AND hcp.owner_table_id = hps.party_id(+)
    AND hps.location_id = hl.location_id
    AND hcp.CONTACT_POINT_TYPE ='PHONE'
    AND hcp.STATUS = 'A';

    Hi,
    Looks like some of your joins are incorrect. Try the below query :
    SELECT hp.party_id, hp.party_name customer_name, cust.account_number,
           hps.party_site_number, hl.address1, hl.address2, hl.address3, hl.city,
           hl.country, hcp.phone_number
      FROM hz_parties hp,
           hz_cust_accounts cust,
           hz_party_sites hps,
           hz_locations hl,
           hz_contact_points hcp
    WHERE cust.party_id = hp.party_id
       AND hp.status = 'A'
       AND cust.status = 'A'
       AND hps.party_id = hp.party_id
       AND hps.status = 'A'
       AND hl.location_id = hps.location_id
       AND hcp.owner_table_name = 'HZ_PARTIES'
       AND hcp.owner_table_id = hp.party_id(+)
    Regards,
    Manjusha.

  • SQL Query to Access Query

    try to place () on segments of criteria; WHERE (p.SvcDate BETWEEN '03/19/2015' AND '06/17/2015') AND (p.PayCode '37')  AND (e.Active = 'Y')  - not sure will fix

    I have the following Query in Access and as it is, it works. I needed to add a new modifier to the "WHERE" clause of "Payroll.PayCode '37' so that it is not taking that paycode into account. Once I added that modifier, the entire query quit working stating that the query was to complex. I proceeded to struggle with the query for a while and eventually broke down and completely recreated the query in MS SQL where I have it working with the Modifier. Once I moved it to Access 2013 I get the same error that the Query is to complex. Could someone please help me out with this. Here is my SQL Query.SQLSELECT p.EmployeeNumber, e.Fname, e.Lname, e.Address, e.City, e.ST, e.Zip, e.DOH, e.DOT, e.DOB, e.[Mrtl Status],e.jobTitle, e.Dept, ROUND(SUM((p.PayUnit)/13),0) AS [13 Week Avg], eb.Eligible, eb.[Agreement Received], eb.[Benefits Term Date],...
    This topic first appeared in the Spiceworks Community

  • Discoverer Report showing Null VS Show SQL query showing results !!!

    I created a simple Cross Tab Discoverer report from a custom SQL which has a calculation for balances. The output is giving all null values even though there are balances. The output doesn't seem right. So I copied the query from Tools-->Show SQL and ran the query in the TOAD where I'm showing balances for the report. I don't understand why it is not showing in the discoverer. Please help.
    Thanks
    Edited by: PA1B on Jan 27, 2010 11:40 AM

    Sorry for late reply.
    Below is the Show SQL query. I don't think the query is application dependent. C_1 is my calculation.
    SELECT o279709.SEGMENT3 as E279727,
    o279709.SEGMENT4 as E279728,
    CASE WHEN o279709.CURRENCY_CODE = 'USD' AND o279709.TRANSLATED_FLAG <> 'Y' THEN SUM(o279709.ENDING_BAL) ELSE 0 END as C_1,
    GROUPING_ID(o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG) as GID
    FROM ( --Foriegn Entity USD Balances
    SELECT                B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                  (select distinct substr(cat.COMPILED_VALUE_ATTRIBUTES,5,1) from apps.fnd_flex_values cat
                   where FLEX_VALUE_SET_ID = (select bat.FLEX_VALUE_SET_ID from apps.fnd_id_flex_structures_vl aat, apps.fnd_id_flex_segments_vl bat
                                                                                                                       where bat.id_flex_code = 'GL#' and
                                                                                                                            bat.id_flex_code = aat.id_flex_code and
                                                                                                                            aat.APPLICATION_ID = bat.APPLICATION_ID and
                                                                                                                            aat.APPLICATION_ID = 101 and
                                                                                                                            bat.SEGMENT_NAME = 'Prime Account' and
                                                                                                                            aat.id_flex_num = bat.id_flex_num
                                                                                                                            and bat.id_flex_num in (select distinct chart_of_accounts_id from apps.gl_code_combinations gat
                                                                                                                                                                              where gat.code_combination_id = A.code_combination_id))
                                       and cat.flex_value = b.segment3) ACCT_TYPE ,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,
                                       C.NAME,
    A.SET_OF_BOOKS_ID,
                                       A.CURRENCY_CODE,A.TRANSLATED_FLAG,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0)) BEG_BAL,
                                  SUM(NVL(A.PERIOD_NET_DR,0)) DEBITS,
    SUM( NVL(A.PERIOD_NET_CR,0)) CREDITS ,
    A.PERIOD_NAME,
                                  SUM(NVL(A.BEGIN_BALANCE_DR,0) - NVL(A.BEGIN_BALANCE_CR,0))+ SUM(NVL(A.PERIOD_NET_DR,0) - NVL(A.PERIOD_NET_CR,0)) ENDING_BAL
    FROM                     APPS.GL_BALANCES A ,
                                       APPS.GL_CODE_COMBINATIONS B,
                                       APPS.GL_SETS_OF_BOOKS     C
    WHERE                     A.CODE_COMBINATION_ID = B.CODE_COMBINATION_ID
    --AND                           A.PERIOD_NAME = 'SEP-09'
    AND                          C.SET_OF_BOOKS_ID = A.SET_OF_BOOKS_ID
    --AND                           A.TRANSLATED_FLAG <> 'Y'
    --AND                           B.SEGMENT1 = '83101'
    --AND                           B.SEGMENT3 = '14602'
    --AND                           A.SET_OF_BOOKS_ID = 77
    --AND                           A.CURRENCY_CODE = 'USD'
    GROUP BY           A.CODE_COMBINATION_ID,
                                  B.SEGMENT1,
                                       B.SEGMENT2,     
                                       B.SEGMENT3,
                                       B.SEGMENT4,
                                       B.SEGMENT5,
                                       B.SEGMENT6,
                                       B.SEGMENT7,
                                       B.SEGMENT8,
                                       B.SEGMENT9,
                                       B.SEGMENT10,
                                       B.SEGMENT11,
                                       B.SEGMENT12,
                                       B.SEGMENT13,          
                                       A.CURRENCY_CODE,
                                       A.TRANSLATED_FLAG,
                                       C.NAME,A.PERIOD_NAME,
    A.SET_OF_BOOKS_ID
    ) o279709
    WHERE (o279709.PERIOD_NAME = 'DEC-09')
    AND (o279709.SET_OF_BOOKS_ID <> 72)
    AND (o279709.SEGMENT12 = '000')
    AND (o279709.SEGMENT3 IN ('10101','10301','10502','12001'))
    AND (o279709.SEGMENT1 IN ('82901','82902','82903','83001','83003','83201'))
    GROUP BY GROUPING SETS(( o279709.CURRENCY_CODE,o279709.SEGMENT3,o279709.SEGMENT4,o279709.TRANSLATED_FLAG ),( o279709.SEGMENT3,o279709.SEGMENT4 ),( o279709.SEGMENT3 ))
    HAVING (GROUP_ID()=0)
    ORDER BY GID DESC;
    Thanks,
    PA1
    Edited by: PA1B on Jan 29, 2010 12:50 PM

Maybe you are looking for

  • Error in Asset Transactions Report in ECC 6

    Hi Friends, We have upgraded from ECC 4.7 to ECC 6.0 in Nov 2007. In Asset Transactions Report (S_ALR_87012048) the Depreciation column is displaying Zero Values for individual line items after November 2007 (ie for Assets posted after Nov, 07). We p

  • Why did my server crash and what to do to prevent this?

    hi there, i've been following the installation guide on single host and all looked well until yesterday all of a sudden i couldn't see my mail tab when using webmail. i tried re-logging in several times and from three computers at home but no mail ta

  • SAP integration kit - MDX parser does not exist

    Hi, While running a query via Web Intelligence, during the process where data should be retrieved, the error pops up that RFC destination MDX PARSER does not exist. The universe is built on an infoCube without intermediate BEx query. I know about the

  • It is possible to sinc the photo's location on iPad and iPhone ?

    It is possible to sinc the photo's location on iPad and iPhone ?

  • Unable to add supplying plant

    Hi, I am unable to add supplying plant for cross company STO in vendor Master. I go to XK02-Purchasing-Extras-Add purchasing data but no tab is coming where I can put the plant.The screen here shows just Data retention at VSR and data retention at pl