Query Question - Linking in Time Span Data to Point-in-Time References

I am trying to pull historical data from a time-span table of records, using another point-in-time reference. I have been unsuccessful.
I've thrown some sample tables and data together to illustrate what I am seeking:
Create Table EmployeeInfo (
       id Number(10,0),               -- Employee ID Number
       Name VarChar2(32 Byte),        -- Employee Name
       CurrentShift VarChar2(2 Byte)  -- Current Employee Shift
Create Table ShiftChanges (
       id Number(10,0),               -- Employee ID that this shift change record is for
       ChangeDate Date,               -- Date that this Change Took Place
       OldShift VarChar2(2 Byte),
       NewShift VarChar2(2 Byte)
Create Table TimeCard(
       id Number(10,0),               -- Employee ID Number for this Timecard
       WorkDay Date,                  -- What Day is this Timecard for?
       Hours Float(63)                -- Number of Hours worked.
COMMIT;
INSERT INTO EmployeeInfo VALUES (100,'John Doe','Days')
INSERT INTO EmployeeInfo VALUES (101,'Jane Doe','Days');
INSERT INTO TimeCard VALUES (100, to_date('01012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (101, to_date('01012010','ddmmyyyy'), 10);
INSERT INTO TimeCard VALUES (100, to_date('02012010','ddmmyyyy'), 9);
INSERT INTO TimeCard VALUES (101, to_date('02012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (100, to_date('03012010','ddmmyyyy'), 8);
INSERT INTO TimeCard VALUES (101, to_date('03012010','ddmmyyyy'), 7);
INSERT INTO ShiftChanges VALUES (100, to_date('02012010','ddmmyyyy'), 'Nights', 'Days');
COMMIT;I could do a query such as:
SELECT TC.id,
       EM.Name,
       TC.Workday,
       EM.CurrentShift AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM
WHERE  (TC.ID=EM.ID(+));But it will not give me the historical shift, only the current. Since John Doe changed shifts on Jan 2 from Nights to Days, the above query would not reflect it.
I have attempted to join the historical table using a less-than operator. This doesn't work since more than one row can be returned.
SELECT TC.id,
       EM.Name,
       TC.Workday,
       SC.NewShift AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM,
       ShiftChanges SC
WHERE  (TC.ID=EM.ID(+)) AND
       (TC.ID=SC.ID(+) AND TC.WORKDAY<=SC.WORKDAY(+));The problem stems from the fact that you need to examine multiple records in one table in order to obtain the correct historical data for the other.
The following SQL script {color:green}does work{color} - if the values are defined ahead of time.
DEFINE EMPID=101;
DEFINE CHGDATE=to_date('01/01/2010','dd/mm/yyyy');
SELECT SQ.Shift
FROM   (SELECT  ShiftChanges.NewShift AS Shift,
                RANK() OVER (ORDER BY ShiftChanges.ChangeDate DESC) R
        FROM    ShiftChanges
        WHERE   ShiftChanges.id = &EMPID AND
                ShiftChanges.ChangeDate <= &CHGDATE
        ) SQ
WHERE R = 1However, I have been unsuccessful in adapting it to the example tables I provided. If I insert the query as an inline subquery* in the select statement, it won't work, since the criteria is nested two levels down, and I can only get parent values within the first level.
I haven't thought of a way I can do this using a nested subquery - I keep running into that problem - how do you link in Time-Span data with a point-in-time reference.
Any ideas / enlightening thoughts?
Thank You
{size:8}_SELECT * FROM V$VERSION information:_
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
"CORE     9.2.0.8.0     Production"
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
{size}
user10879184 re-wrote the original post on 29-Mar-2010 1:21 PM to reflect suggestions made by poster.

I changed the tables to hold VARCHAR2(6) shift information and your query to reference the ChangeDate column.
I also assume you meant to link a TimeCard entry with the most previous ShiftChange entry rather than one that occurs after the time worked (TC.WORKDAY>=SC.CHANGEDATE(+) rather than TC.WORKDAY<=SC.CHANGEDATE(+)):
Another issue you don't take into account the case where there has been no shift change. In that event you need the current shift from the EmployeeInfo table which is taken care of with the NVL function.
You correctly note that multiple shift change records will result in duplicate TimeCard records though your test data fails to check for that condition. I added this row:
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('03012010','ddmmyyyy'), 'Days', 'Nights'); Now it is apparent
SQL> SELECT TC.id,
  2         EM.Name,
  3         TC.Workday,
  4         NVL(SC.NewShift,EM.CurrentShift) AS Shift
  5  FROM   TimeCard TC,
  6         EmployeeInfo EM,
  7         ShiftChanges SC
  8  WHERE  TC.ID=EM.ID(+) AND
  9         TC.ID=SC.ID(+) AND TC.WORKDAY>=SC.CHANGEDATE(+);
        ID NAME                             WORKDAY   SHIFT
       100 John Doe                         01-JAN-10 Days
       100 John Doe                         02-JAN-10 Days
       100 John Doe                         03-JAN-10 Days
       100 John Doe                         03-JAN-10 Nights
       101 Jane Doe                         01-JAN-10 Days
       101 Jane Doe                         02-JAN-10 Days
       101 Jane Doe                         03-JAN-10 Days
7 rows selected.The reason for the duplicate Jan3 time is the two shift change records. We are matching both ShiftChange records that occured before the 3rd.
We also see that your test data has John starting out on Days and then shifting from Nights to Days on the 2nd for no real change. Fixing that:
SQL> DELETE from ShiftChanges where ID = 100;
2 rows deleted.
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('02012010','ddmmyyyy'), 'Days', 'Nights');
1 row created.
SQL> INSERT INTO ShiftChanges VALUES (100, to_date('03012010','ddmmyyyy'), 'Nights', 'Days');
1 row created.Then:
SQL> SELECT TC.id,
  2         EM.Name,
  3         TC.Workday,
  4         NVL(SC.NewShift,EM.CurrentShift) AS Shift
  5  FROM   TimeCard TC,
  6         EmployeeInfo EM,
  7         (SELECT ID, Workday, ChangeDate, NewShift
  8          FROM
  9                 (SELECT TC2.ID, TC2.Workday, SC2.ChangeDate, SC2.Newshift,
10                         MAX (SC2.ChangeDate) KEEP (DENSE_RANK LAST ORDER BY SC2.ChangeDate)
11                                              OVER (PARTITION BY SC2.ID, TC2.Workday) AS Max_ChangeDate
12                  FROM   ShiftChanges SC2,
13                         TimeCard TC2
14                  WHERE  TC2.Workday >= SC2.ChangeDate
15                  AND    TC2.ID = SC2.ID
16                  )
17          WHERE   ChangeDate = Max_ChangeDate
18          ) SC
19  WHERE  TC.ID=EM.ID(+) AND
20         TC.ID=SC.ID(+) AND
21         TC.Workday=SC.ChangeDate(+) AND
22         TC.Workday = SC.Workday(+);
        ID NAME                             WORKDAY   SHIFT
       100 John Doe                         01-JAN-10 Days
       100 John Doe                         02-JAN-10 Nights
       100 John Doe                         03-JAN-10 Days
       101 Jane Doe                         01-JAN-10 Days
       101 Jane Doe                         02-JAN-10 Days
       101 Jane Doe                         03-JAN-10 Days
6 rows selected.The inline view finds the greatest ChangeDate less than the TimeCard Workday for each Workday.

Similar Messages

  • Sql query-filter if 1 set of data exists and in the same time 2 set doesnt

    Hi guys,
    I need to write a query where I filter on certain data being present, but in the same time other data from the same table being not present.
    For example:
    ProceduresTable:
    Type 1
    Type 1
    Type 2
    Type 2
    Type 1
    MyTable:
    Name
    OtherFields
    JoiningTable (many to many)
    ProceduresTable_Key
    MyTable_Key
    I need to select all records from MyTable and Procedures for which there are procedures from Type 1 but there are no procedures from Type 2 in the same time.
    So far I've been only able to do that by using subqueries and I think there should be an easier way to do that.
    Here is what I have:
    Select * From MyTable, Procedures, JoiningTable Where JOINING_CONDITIONS AND Type = 1 AND NAME_SOME_COLUMN NOT IN (SELECT NAME_SOME_COLUMN FROM ... WHERE Type = 2 and inner.Name = outer.Name)
    Hope you understand my meta code. I have Oracle 9 db.
    Thanks a lot!

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps if you post a specific example. Include CREATE TABLE and INSERT statements for a little sample data, and also post the results you want from that data.
    if you can use commonly available tables (like those in the scott or hr schemas) to illustrate your proble, then you don't have to post the sample data; just the results.
    For example, I think you're asking something like this:
    "How can I find information about people in the sciott.emp table who are in a department that has at least one CLERK ( that is, a row with job='CLERK') but no SALESMAN? That is, I want these results:
    {code}
    ENAME DEPTNO JOB
    CLARK 10 MANAGER
    KING 10 PRESIDENT
    MILLER 10 CLERK
    JONES 20 MANAGER
    FORD 20 ANALYST
    ADAMS 20 CLERK
    SMITH 20 CLERK
    SCOTT 20 ANALYST
    {code}
    One way is to use CASE expressions instead of WHERE clauses to test for the criteria, then using the reults of the CASE expressions in the WHERE clause.
    For example:
    WITH     got_cnts     AS
         SELECT     ename,     deptno,     job
         ,     COUNT ( CASE
                             WHEN  job = 'CLERK'
                       THEN  1
                         END
                    ) OVER (PARTITION BY deptno)     AS clerk_cnt
         ,     COUNT ( CASE
                             WHEN  job = 'SALESMAN'
                       THEN  1
                         END
                    )     OVER (PARTITION BY deptno)     AS salesman_cnt
         FROM     scott.emp
    SELECT     ename,     deptno,     job
    FROM     got_cnts
    WHERE     clerk_cnt     > 0
    AND     salesman_cnt     = 0
    ;The problem here is that you can't always tell, by looking at any one row, if it should be included or not; in this case, you need to know something about the department as a whole. Analytic functions can look at the department as a whole, but analytic functions are computed after the WHERE clause is applied, so to use the results of the analytic functions in a WHERE clause, we need to do the analytics first, in a sub-query, and the WHERE clause later.
    Sometimes (as in the example above) analytic functions are useful; other times, aggregate functions are more appropriate, depending on the exact requirements.
    Edited by: Frank Kulash on Apr 12, 2010 9:00 AM

  • I have reached full memory capacity on my 500GB Time Capsule. I am considering purchasing a 2TB Time Capsule. Do I need to resave all existing data on the new hard drive or can I start afresh? Or can I link both time capsules to operate independantly?

    Hi,
    I  have reached full memory capacity on my 500GB Time Capsule. I am considering purchasing a 2TB Time Capsule.
    a) Do I need to resave all existing data on the new hard drive or can I start afresh?
    b) Or can I link both time capsules to operate independantly?
    Thanks,
    Paul

    You may not need to buy a new Time Capsule. 
    You can connect a USB drive to the Time Capsule, and use it in addition to the TC's internal HD.  You may need a powered USB hub as well.
    Exactly what is on your TC?  If it's only Time Machine backups, you may not need to do anything -- Time Machine will delete the oldest backup(s) automatically when it needs room for new ones.  But if you have more than about 250 GB on your internal HD, that 500 GB may not be large enough to keep backups long enough.
    If you have other data on the TC's internal HD, besides your backups, you could back up to the external HD and use the internal for the other data, or vice-versa.  But TM backups cannot "span" two drives, and you shouldn't mix backups and other data on the TC's internal HD.

  • Query to search between two specific dates and time period

    Hi,
    Need a query to search between two particular dates and time period
    Like i want to search table having one date field .
    Suppose the date range is '01-JUL-06' and '01-AUG-06' and time frame
    is 23:00:00 to 08:00:00
    i.e i want to search between dates 01 july to 01 aug and also within the time frame i.e 23:00 to 08:00 hrs only

    The general principle is
    SELECT * FROM your_table
    WHERE some_date BEWTEEN to_date('01-JUL-06') and to_date('01-AUG-06' )+0.99999
    AND  ( some_date <= trunc(some_date)+8/24
               OR  some_date >= trunc(some_date)+23/24 )
    /Cheers, APC

  • How to link two modules of data when querying the data ?

    Hi ,
    I am using Designer editor to create a form .
    I am having two modules with the tables EMPLOYEE and department .
    In my form ,I want to display the data of each employee with the department data .
    How to link the two tables data in the designer ?
    How to View the generated triggers in the designer ?
    Thanks
    Sai

    Two modules means two forms. These are unrelated.
    Or do you mean that you have one form with two blocks (master-detail)?
    How to link the two tables data in the designer ?You have to define the foreign key on the tables. Based on this FK Forms Generator will generate the code if you create two Module Components (master-detail) in the module. Don't forget to define the Key Based Link on the master block.
    How to View the generated triggers in the designer ?You can't. You have tom open the generated FMB file in Forms Builder to see what code is generated.

  • Convert char to date and query question

    Hi,
    I am working on Oracle database 9i.
    I have t to insert date columns of creation_date and last_update_date from table Y to another table X in a character format YYYYMMDD. I did that with the following:
    replace(to_char(sysdate,'YYYY/MM/DD'),'/')
    My first question is how can I change the format again to oracle date when I read from table X?
    My second question I want to read data from table Y to table Z on the following condition:
      rows exist in both table but the last update_date in table Y is greater than the last_update_date in table Z  . How can I achieve this?
    thank you

    Hi,
    AHS wrote:
    Hi,
    I am working on Oracle database 9i.
    I have t to insert date columns of creation_date and last_update_date from table Y to another table X in a character format YYYYMMDD. I did that with the following:
    replace(to_char(sysdate,'YYYY/MM/DD'),'/')
    My first question is how can I change the format again to oracle date when I read from table X?
    My second question I want to read data from table Y to table Z on the following condition:
      rows exist in both table but the last update_date in table Y is greater than the last_update_date in table Z  . How can I achieve this?
    thank you
    If you want to show the current date in 'YYYYMMDD' format without '/' characters, then use 'YYYYMMDD' format without '/' characters:
    TO_CHAR (SYSDATE, 'YYYYMMDD')
    There's no need for REPLACE.
    Justin is right (as usual).  Keep date information in DATE columns.  If you need to display a DATE in a particular format, use TO_CHAR when displaying it (or use "ALTER SESSION SET NLS_DATE_FORMAT" to change the default display format for all DATEs).
    For your second question, start a second thread.
    Whenever you have  question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ:
    The second problem sounds like a job for the analytic MAX function.

  • How to find out which query run how many times using ST03?

    Hi experts,
    I am trying to clean up all the junk queries in BWP. my questions is, How to find out that the particular query ran how my times in a year and by which user using ST03, How to do it step by step?
    I don't like to use statistic reports for this. How to do it using ST03?
    Please let me know. Thanks in advance.
    Sharat.

    Hi,
    Please find the below links which would help you solving you problem,
    SAP BW performance tunning : Includes screen shots
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/68fbb490-0201-0010-8eb5-f7e0adaff5bd
    SAP BW Query Performance Tuning with Aggregates:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3f66ba90-0201-0010-ac8d-b61d8fd9abe9
    With Regards,
    PCR

  • Question to recruitment/Appl. master data u2013 PB40.

    Hi, I have a question to recruitment/Appl. master data u2013 PB40.
    Maybe someone can help?
    I have created an own candidate action similar to the SAP action u201CInitial entry of basic data.u201D
    The Customizing of the new action is the same like that of the SAP action.
    The problem is that the masks are different:
    The original SAP action "Initial entry of basic data" starts with:
    Transaction: PB40
    Program (screen): SAPMPAP4
    Screen number: 100
    Program (GUI): SAPMPAP4
    GUI status: FAS1
    The action I created starts with:
    Transaction: PB40
    Program (screen): MP400000
    Screen number: 2000
    Program (GUI): MP400000
    GUI Status: INS
    Why do the program, the screen number and the GUI status differ and how to change it?
    Thanks in advance!
    Yours sincerely,
    Thomas

    any talented  guy do this way.
    i think  that ur working  in E2E project work
    before  singoff ur business process u should give to ur users  master data templets..they collect for  masterdatas in before realization phase...that time  u should know  how many specifications is there and  in spections how  many in quantitative and how many qualitative u will indentify. if any query let me  back.
    Edited by: Lakshmiananda prasad on Oct 6, 2009 11:48 AM

  • UCCX 10.1 - Linked Server - Copying HR data to external SQL Server for reporting

    I have a customer that is migrating from UCCX 7 to UCCX 10.  They currently have a 2008 SQL Server R2 that they use for custom reports.  They have a package that runs nightly to copy relevant data from UCCX 7 to the their server and then run reports daily against that database.   Pretty easy when everything is in MS SQL.  My plan was to set up a linked server in SQL 2008 to the UCCX server.  This would allow me to easily run a query against Informix and move the data over as before.  However, I am having problems adding the linked server.
    I have installed the Informix drivers (both 32 and 64 bit) during the troubleshooting.
    The DSN is created and connects to UCCX just fine.
    When I attempt to add the linked server using 64 bit driver DSN I get the following:
    Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "UCCX101".
    OLE DB provider "MSDASQL" for linked server "UCCX101" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
    OLE DB provider "MSDASQL" for linked server "UCCX101" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
    OLE DB provider "MSDASQL" for linked server "UCCX101" returned message "[Informix][Informix ODBC Driver][-11302] Insufficient Connection information was supplied". (.Net SqlClient Data Provider)
    When I attempt to add the linked server using the 32 bit driver DSN I get the following:
    Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "32UCCX101".
    OLE DB provider "MSDASQL" for linked server "32UCCX101" returned message "[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application". (Microsoft SQL Server, Error: 7303)
    It appears to me there is a 32/64 bit conflict no matter route I go.
    Can anyone tell me what I am missing?
    Is there a better approach to take to achieve the ultimate goal?
    Any suggestions are greatly appreciated.
    TIA
    John

    I have created linked servers on an SQL2K box that points back to CCX. First off, you have to set the password for the UCCX HR user to some known value.
    exec sp_dropserver 'fonccx9_01', 'droplogins'
    EXEC sp_addlinkedserver
    @server='fonccx9_01', -- Name of the Linked Server, when it is created.
    @srvproduct='Microsoft OLE DB Provider for ODBC', -- OLE DB Provider.
    @provider='MSDASQL', -- Provider_name.
    @datasrc ='fonccx9-01', -- DSN Name of the ODBC Data Source.
    @provstr= -- ODBC Connection String.
    'Driver={IBM Informix ODBC};Server=fonccx9_01_uccx;Database=db_cra; Uid=uccxhruser; Pwd=Some-Password;'
    EXEC sp_addlinkedsrvlogin
        @rmtsrvname = 'fonccx9_01',
        @useself = 'FALSE',
        @rmtuser = 'uccxhruser',
        @rmtpassword = 'Some-Password'
    Note that the server name is "fonccx9-01", but the dash is an illegal character in the server name, so you have to change that to an underscore. You still have to manually build the ODBC data source on the box where you are trying to create the linked server.

  • Sql query is taking more time

    Hi all,
    db:oracle 9i
    I am facing below query prob.
    prob is that query is taking more time 45 min than earliar (10 sec).
    please any one suggest me .....
    SQL> SELECT MAX (tdar1.ID) ID, tdar1.request_id, tdar1.lolm_transaction_id,
    2 tdar1.transaction_version
    3 FROM transaction_data_arc tdar1
    4 WHERE tdar1.transaction_name ='O96U '
    5 AND tdar1.transaction_type = 'REQUEST'
    6 AND tdar1.message_type_code ='PCN'
    7 AND NOT EXISTS (
    8 SELECT NULL
    9 FROM transaction_data_arc tdar2
    10 WHERE tdar2.request_id = tdar1.request_id
    11 AND tdar2.lolm_transaction_id != tdar1.lolm_transaction_id
    12 AND tdar2.ID > tdar1.ID)
    13 GROUP BY tdar1.request_id,
    14 tdar1.lolm_transaction_id,
    15 tdar1.transaction_version;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=17 Card=1 Bytes=42)
    1 0 SORT (GROUP BY) (Cost=12 Card=1 Bytes=42)
    2 1 FILTER
    3 2 TABLE ACCESS (BY INDEX ROWID) OF 'TRANSACTION_DATA_ARC
    ' (Cost=1 Card=1 Bytes=42)
    4 3 INDEX (RANGE SCAN) OF 'NK_TDAR_2' (NON-UNIQUE) (Cost
    =3 Card=1)
    5 2 TABLE ACCESS (BY INDEX ROWID) OF 'TRANSACTION_DATA_ARC
    ' (Cost=5 Card=918 Bytes=20196)
    6 5 INDEX (RANGE SCAN) OF 'NK_TDAR_7' (NON-UNIQUE) (Cost
    =8 Card=4760)

    prob is that query is taking more time 45 min than earliar (10 sec).Then something must have changed (data growth/stale statistics/...?).
    You should post as much details as possible, how and what it is described in the FAQ, see:
    *3. How to improve the performance of my query? / My query is running slow*.
    When your query takes too long...
    How to post a SQL statement tuning request
    SQL and PL/SQL FAQ
    Also, given your database version, using NOT IN instead of NOT EXISTS might make a difference (but they're not the same).
    See: SQL and PL/SQL FAQ

  • Query is taking more time to execute in PROD

    Hi All,
    Can anyone tell me why this query is taking more time when I am using for single trx_number record it is working fine but when I am trying to use all the records it is not fatching any records and it is keep on running.
    SELECT DISTINCT OOH.HEADER_ID
    ,OOH.ORG_ID
    ,ct.CUSTOMER_TRX_ID
    ,ool.ship_from_org_id
    ,ct.trx_number IDP_SHIPMENT_ID
    ,ctt.type STATUS_CODE
    ,SYSDATE STATUS_DATE
    ,ooh.attribute16 IDP_ORDER_NBR --Change based on testing on 21-JUL-2010 in UAT
    ,lpad(rac_bill.account_number,6,0) IDP_BILL_TO_CUSTOMER_NBR
    ,rac_bill.orig_system_reference
    ,rac_ship_party.party_name SHIP_TO_NAME
    ,raa_ship_loc.address1 SHIP_TO_ADDR1
    ,raa_ship_loc.address2 SHIP_TO_ADDR2
    ,raa_ship_loc.address3 SHIP_TO_ADDR3
    ,raa_ship_loc.address4 SHIP_TO_ADDR4
    ,raa_ship_loc.city SHIP_TO_CITY
    ,NVL(raa_ship_loc.state,raa_ship_loc.province) SHIP_TO_STATE
    ,raa_ship_loc.country SHIP_TO_COUNTRY_NAME
    ,raa_ship_loc.postal_code SHIP_TO_ZIP
    ,ooh.CUST_PO_NUMBER CUSTOMER_ORDER_NBR
    ,ooh.creation_date CUSTOMER_ORDER_DATE
    ,ool.actual_shipment_date DATE_SHIPPED
    ,DECODE(mp.organization_code,'CHP', 'CHESAPEAKE'
    ,'CSB', 'CHESAPEAKE'
    ,'DEP', 'CHESAPEAKE'
    ,'CHESAPEAKE') SHIPPED_FROM_LOCATION --'MEMPHIS' --'HOUSTON'
    ,ooh.freight_carrier_code FREIGHT_CARRIER
    ,NVL(XX_FSG_NA_FASTRAQ_IFACE.get_invoice_amount ('FREIGHT',ct.customer_trx_id,ct.org_id),0)
    + NVL(XX_FSG_NA_FASTRAQ_IFACE.get_line_fr_amt ('FREIGHT',ct.customer_trx_id,ct.org_id),0)FREIGHT_CHARGE
    ,ooh.freight_terms_code FREIGHT_TERMS
    ,'' IDP_BILL_OF_LADING
    ,(SELECT WAYBILL
    FROM WSH_DELIVERY_DETAILS_OE_V
    WHERE -1=-1
    AND SOURCE_HEADER_ID = ooh.header_id
    AND SOURCE_LINE_ID = ool.line_id
    AND ROWNUM =1) WAYBILL_CARRIER
    ,'' CONTAINERS
    ,ct.trx_number INVOICE_NBR
    ,ct.trx_date INVOICE_DATE
    ,NVL(XX_FSG_NA_FASTRAQ_IFACE.get_invoice_amount ('LINE',ct.customer_trx_id,ct.org_id),0) +
    NVL(XX_FSG_NA_FASTRAQ_IFACE.get_invoice_amount ('TAX',ct.customer_trx_id,ct.org_id),0) +
    NVL(XX_FSG_NA_FASTRAQ_IFACE.get_invoice_amount ('FREIGHT',ct.customer_trx_id,ct.org_id),0)INVOICE_AMOUNT
    ,NULL IDP_TAX_IDENTIFICATION_NBR
    ,NVL(XX_FSG_NA_FASTRAQ_IFACE.get_invoice_amount ('TAX',ct.customer_trx_id,ct.org_id),0) TAX_AMOUNT_1
    ,NULL TAX_DESC_1
    ,NULL TAX_AMOUNT_2
    ,NULL TAX_DESC_2
    ,rt.name PAYMENT_TERMS
    ,NULL RELATED_INVOICE_NBR
    ,'Y' INVOICE_PRINT_FLAG
    FROM ra_customer_trx_all ct
    ,ra_cust_trx_types_all ctt
    ,hz_cust_accounts rac_ship
    ,hz_cust_accounts rac_bill
    ,hz_parties rac_ship_party
    ,hz_locations raa_ship_loc
    ,hz_party_sites raa_ship_ps
    ,hz_cust_acct_sites_all raa_ship
    ,hz_cust_site_uses_all su_ship
    ,ra_customer_trx_lines_all rctl
    ,oe_order_lines_all ool
    ,oe_order_headers_all ooh
    ,mtl_parameters mp
    ,ra_terms rt
    ,OE_ORDER_SOURCES oos
    ,XLA_AR_INV_AEL_SL_V XLA_AEL_SL_V
    WHERE ct.cust_trx_type_id = ctt.cust_trx_type_id
    AND ctt.TYPE <> 'BR'
    AND ct.org_id = ctt.org_id
    AND ct.ship_to_customer_id = rac_ship.cust_account_id
    AND ct.bill_to_customer_id = rac_bill.cust_account_id
    AND rac_ship.party_id = rac_ship_party.party_id
    AND su_ship.cust_acct_site_id = raa_ship.cust_acct_site_id
    AND raa_ship.party_site_id = raa_ship_ps.party_site_id
    AND raa_ship_loc.location_id = raa_ship_ps.location_id
    AND ct.ship_to_site_use_id = su_ship.site_use_id
    AND su_ship.org_id = ct.org_id
    AND raa_ship.org_id = ct.org_id
    AND ct.customer_trx_id = rctl.customer_trx_id
    AND ct.org_id = rctl.org_id
    AND rctl.interface_line_attribute6 = to_char(ool.line_id)
    AND rctl.org_id = ool.org_id
    AND ool.header_id = ooh.header_id
    AND ool.org_id = ooh.org_id
    AND mp.organization_id = ool.ship_from_org_id
    AND ooh.payment_term_id = rt.term_id
    AND xla_ael_sl_v.last_update_date >= NVL(p_last_update_date,xla_ael_sl_v.last_update_date)
    AND ooh.order_source_id = oos.order_source_id --Change based on testing on 19-May-2010
    AND oos.name = 'FASTRAQ' --Change based on testing on 19-May-2010
    AND ooh.org_id = g_org_id --Change based on testing on 19-May-2010
    AND ool.flow_status_code = 'CLOSED'
    AND xla_ael_sl_v.trx_hdr_id = ct.customer_trx_id
    AND trx_hdr_table = 'CT'
    AND xla_ael_sl_v.gl_transfer_status = 'Y'
    AND xla_ael_sl_v.accounted_dr IS NOT NULL
    AND xla_ael_sl_v.org_id = ct.org_id;
    -- AND ct.trx_number = '2000080';
    }

    Hello Friend,
    You query will definitely take more time or even fail in PROD,becuase the way it is written. Here are my few observations, may be it can help :-
    1. XLA_AR_INV_AEL_SL_V XLA_AEL_SL_V : Never use a view inside such a long query , becuase View is just a window to the records.
    and when used to join other table records, then all those tables which are used to create a view also becomes part of joining conition.
    First of all please check if you really need this view. I guess you are using to check if the records have been created as Journal entries or not ?
    Please check the possbility of finding it through other AR tables.
    2. Remove _ALL tables instead use the corresponding org specific views (if you are in 11i ) or the sysnonymns ( in R12 )
    For example : For ra_cust_trx_types_all use ra_cust_trx_types.
    This will ensure that the query will execute only for those ORG_IDs which are assigned to that responsibility.
    3. Check with the DBA whether the GATHER SCHEMA STATS have been run atleast for ONT and RA tables.
    You can also check the same using
    SELECT LAST_ANALYZED FROM ALL_TABLES WHERE TABLE_NAME = 'ra_customer_trx_all'.
    If the tables are not analyzed , the CBO will not be able to tune your query.
    4. Try to remove the DISTINCT keyword. This is the MAJOR reason for this problem.
    5. If its a report , try to separate the logic in separate queries ( using a procedure ) and then populate the whole data in custom table, and use this custom table for generating the
    report.
    Thanks,
    Neeraj Shrivastava
    [email protected]
    Edited by: user9352949 on Oct 1, 2010 8:02 PM
    Edited by: user9352949 on Oct 1, 2010 8:03 PM

  • Parsing the query takes too much time.

    Hello.
    I hitting the bug in в Oracle XE (parsing some query takes too much time).
    A similar bug was previously found in the commercial release and was successfully fixed (SR Number 3-3301916511).
    Please, raise a bug for Oracle XE.
    Steps to reproduce the issue:
    1. Extract files from testcase_dump.zip and testcase_sql.zip
    2. Under username SYSTEM execute script schema.sql
    3. Import data from file TESTCASE14.DMP
    4. Under username SYSTEM execute script testcase14.sql
    SQL text can be downloaded from http://files.mail.ru/DJTTE3
    Datapump dump of testcase can be downloaded from http://files.mail.ru/EC1J36
    Regards,
    Viacheslav.

    Bug number? Version fix applies to?
    Relevant Note that describes the problem and points out bug/patch availability?
    With a little luck some PSEs might be "backported", since 11g XE is not base release e.g. 11.2.0.1.

  • Fico interview questions and Real time tickets with resoving details

    MODERATOR:  Do not post (or request) email address or links to copyrighted or confidential information on these forums.  If you do, the thread will be LOCKED and all points UNASSIGNED.
    hi sap gurus
                    i have done sap-fico iam in job trails. can any body help me    Fico interview questions and Real time tickets with resoving details
    regards
    prasad.v
    Edited by: chinna prasad on Jun 5, 2008 4:10 PM

    Hello Prasad,
    Before attending interviews.....First you need to understand general things like CV writing, projects, sub modules etc., you should be gain knowledge on these concepts then you can move further.
    1. CV 2.Projects 3.your strenths in sap (reading..reading...reading....practice...practice...practice)
    2.you please interact with your friends who is on trails, then you can get more information like interview process, methodology, technical etc.,
    I am sending some real time interview tech questions which will useful for you.
    Questions:
    1.When tickets are raised by end users who will give priority? After resolve the tickets who will close the status?
    2.In real time at a time how many normal periods, special periods, MM periods we can open?
    3.What is client dependant & Independent?
    4.How to transport configuration settings from one client to another client or production client, which tools we can use for transport?
    5.Why we donu2019t assign business area to company code?
    6.What is the difference between General GL A/c, Control A/c, Reconciliation A/c & Offsetting A/c?
    Answers:
    1.The priority is generally decided by the Coordinator on the client side. After tickets are resolved, they will have to be closed by the coordinator on the customer site
    2. In FI as many as you wants. In MM only 2 (current month + previous
    3.Certain tables and customizations made in one client will affect the other clients also - then it is cross client i.e, client dependent. While if the changes made in one client has no impact on the other client - it is said to be client independent
    4.Transports from one server to the other can be made with the help of transport requests. When a configuration is done the system generates a request number. First release the task and then release the request. Use TC-SE10 / SE09, SE09: workbench transport; SE10: customizing transport. But currently no such difference actually exists.
    5.because in case of multiple company codes, same business area can be used across company codes. Business area is cross company code, means it is not confined to one company code thatu2019s why we don't assign BA to any of the company codes. It is client dependant, not company code dependant. We can pass values from one company code to any of the BA in that client.
    6.General GL Account are those used for standard posting like for example Income and Expenses Accounts
    - Control Account are basically used for reconciliation between modules like FI and CO, to ensure that both the modules are in sync.
    - Reconciliation Account are those specific covering ADK (A-Assets, D-Customer, K-Vendor). For example a Customer Master would be mapped to a Bills Receivable Reconciliation Account and any transaction that needs to be posted are done against the customer code.
    - Offsetting Account are used for variety of reasons and few examples are Intercompany Postings, at the time of Implementation when TB and Balance sheet are uploaded would be offsetted against a dummy account.
    All the best.....dont forget and pl assign points if useful and if u have any querries pl revert back
    thanks
    Anil

  • Some question on IDOC (Control Record/Data Record/Status Record)

    Dear all,
    I am new in this area, and would like to enquire some question on this topic.
    When I view a IDOC via WE02, each of the IDOC record will consist of Control Record/Data Record/Status Record).
    Questions:
    I notice that the data records consists of many segment (i.e. E1EDK01, etc) which are use to store application data.
    1 - My question is do I have to manually create all these segment and do a mapping to my application field one by one (i.e. that is when I want to create a brand new message type from scratch)?
    2 - If question no. 1 is Yes, how to do it, what are the transaction code to create it? can you show me the step by step.
    3 - I don't have to create the Control record and the status record for my new message type right ? because those field value will automatically pull out from partner profile and system status message, am I correct?
    Thanks.
    Tuff

    Hi Tuff,
    As everything in SAP, with IDOCs too there are
    1) Standard IDOCs
    2) Standard IDOCs(Extending - Enhancement to an IDOC, to accomodate for custom values)
    3) Custom IDOCs
    And every IDOC has,
    Control record - EDIDC Structure - This mostly reflects the partner profile information, along with few more details which are used for IDOC extension, Sequencing etc
    Data Records - EDID4 Structure - These records contain the actual business data of the document in concern. So for ORDERS05 it would contain order details, INVOIC02 - Invoice details so on...
    Status Records - These records capture the status of an IDOC from the time it is received/sent from your system and a corresponding business document is created/changed. So this will have messages like "IDOC sent to the port OK" etc which are status from the communication layer(ALE) to application specific messages like "Sales Order XXX created" or "Invalid Material" etc.
    You would have noticed something called as Process code in the partner profile, this is associated with a FM(or work flow task etc) which has the business logic coded in.
    So in case of an Inbound IDOC, the sending system updates the IDOC - Control and Data records, and sends it to the receiving system. On the receiving system the IDOC's control record is validated against the partner profiles set, if an entry is found then using the process code it finds the associated FM which will decode the data from the IDOC data records as per the IDOC type and then use it to post data into SAP (VIA BDC, Batch Input, BAPI etc).
    And all this while the Status records are being updated accordingly.
    So with the above context will try to answer your questions,
    1 - My question is do I have to manually create all these segment and do a mapping to my application field one by one (i.e. that is when I want to create a brand new message type from scratch)?
    In case of a custom IDOC, yes you will have  to.
    In case of a standard IDOC, you wouldn't have you just have set up the necessary configuration (Partner Profile, Process code etc)
    In case of a standard IDOC extended to accommodate for some custom values(for which there are no fields in standard IDOC - Let us say you have added some new fields on VA01) - In this case you can still use the standard Process code and Standard FM associated with it, SAP provides several Function exits in these FM's which you can leverage to add your custom logic.
    2 - If question no. 1 is Yes, how to do it, what are the transaction code to create it? can you show me the step by step.
    There are several documents available on the net and on SDN detailing step by step approach for all the above three cases,
    just search for step by step guide for IDOCS - sap.
    3 - I don't have to create the Control record and the status record for my new message type right ? because those field value will automatically pull out from partner profile and system status message, am I correct?
    Again it depends, in case of using a standard IDOC you wouldn't have to. But in case you have some customizations/enhancements then you might have to.
    For Ex: updating the control record accordingly for indicating that you have extended the standard IDOC. Or append custom messages to the status record as per the business logic.
    Try out the examples you find on the net and post any specific questions you might have.
    Regards,
    Chen

  • Query executes faster 2nd time

    Hi,
    So, the result% parameters are as follows, on a specific instance:
    AME                                                                                   TYPE VALUE
    result_cache_mode                                                                         2 MANUAL
    result_cache_max_size                                                                     6 20971520
    result_cache_max_result                                                                   3 5
    result_cache_remote_expiration                                                            3 0
    Executed in 0,156 secondsWell, if i run first time a large query, which takes much time (WITHOUT result_cache hint), this executes in 10 minutes. Then, some of my collegue said me second time i run the query i obtain the results faster than the first time, but i told him caching is not enabled, so why we got faster the results? The query execution plan is the same.
    So, are any buffers, or something, from which the database retrieves the results when executing again that query? Or any explanation why it executes faster on subsequent invocations?
    Thanks

    Roger22 wrote:
    So even if the result caching is not used, the data can be retrieved from the buffers.? okA fundamental concept for all databases and all modern file systems. A read-write memory cache that sits between the s/w and spinning rust.
    Also the basic reason why measuring performance for comparison using elapsed time is flawed - as the very SAME query with the SAME execution plan on the SAME data can show DIFFERENT elapsed times. Amount of I/O is constant, but the type of I/O (logical/fast versus physical/slow) is not.

Maybe you are looking for