By status of line Worktime

Hello

Right now I'm working on the report that provide information how many hours of overtime, although users calling for additional hours is quite inaccurate, what I hear is best explained by an example.  Let's say someone needs to leave work early tomorrow, say it works normally from 8 to 16, and he needs to leave at 15:00, for example for her child from the school. If the Director agrees that he can write that someone actually worked from 8 to 16, but there - 1 to his working time and later that week / month that someone will have to work 8 to 17 to workoff this-1 and Manager will note again that he had been working normally 8-16 but with + 1 - working time.    It works in two ways, someone may say that it will work with the time now and it "will answer" his hours later in the month, etc..

I have the tables:

Old_worktime (User_id number, number of working time)

Current_worktime (DT date, user_id number, number of working time)

In old_worktime I have data that has been preserved in excel earlier, is a line by user_id with the sum of the working time he had on the system startup

In current_worktime managers to put the current date (DT column), User_ID, and how much the user have hours additional (e.g. + 1) or how it worked (-1)

This system is used from 1 March

so

select user_id , sum(worktime) from {
     select dt,user_id,worktime from current_worktime
     union all
     select to_date('2015-02-29','YYYY-MM-DD'),user_id,worktime from old_worktime
} group by user_id

Make me the current value of worktime by user.

Now to the point...

Because now the managers would like to see the history of the user, but with rank Total_worktime value as well...

ex.

Date
User_id
WorkTime
Total_Worktime

2015 02-291234+ 10102015 03-101234-552015 03-121234-502015 03-141234-1-12015-03-161234+ 21

etc.

Also I would total_worktime to be generated in a view, because... eh well put simply managers can update the lines in current_worktime, still the "old", I can't add the column to the current_worktime table and keep it because it can change, and if old line changes more recent lines should be changed also.

I thought the lag function but I can't make it work, I feel that it's pretty easy, but I can't very well

Hello

You are on the right track with SUM.

The lump SUM will give you a total for each group.  It's not what you need.

The analytical SUM will give you a total for each line, i.e. a total cumulative or "running".  This is what you need.

Here's one way:

SELECT dt

user_id

working time

,         NVL ( (

SELECT ow.worktime

Of old_worktime oe

WHERE ow.user_id = cw.user_id

)

0

) + SUM (worktime) over (PARTITION BY user_id

ORDER BY dt

) AS total_worktime

OF current_worktime cw

ORDER BY user_id

,         dt

;

If you would care to post CREATE TABLE and INSERT statements for some sample data and accurate results, you want to go (if different from what you have already posted) SAMPLES then I could test it.

Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

I used a scalar subquery above to get the value of old_worktime.  You could use an outer join.

Tags: Database

Similar Questions

  • How to find the status of lines (modified or not)

    Hello

    Is it possible to find if a line status is modified (but not committed) and user who made the change?
    Avoid locking if we want to check if there is a line in our select statement can cause the deadlock.

    your response is so much appreciated

    In this case, you can skip all the locked rows. This is a clause without papers prior to Oracle 11 g. The following code illustrates the approach:

    // we create a test table with 10 rows
    SQL> create table footab as
      2  select rownum as FOO_ID, object_name as VALUE from all_objects where owner = 'SYS' and rownum  < 11;
    
    Table created.
    
    // we create a procedure that will pretend to be another session trying to update the table, while
    // we are busy updating some rows (it is an autonomous transaction)
    SQL> create or replace procedure UpdateFoo is
      2          pragma autonomous_transaction;
      3
      4          cursor c is
      5          select
      6                  f.*
      7          from    footab f
      8          for update
      9          skip locked;
     10
     11          type TBuffer is table of c%rowtype;
     12          buffer TBuffer;
     13  begin
     14          -- an ugly loop hack used to demonstrate what it can lock
     15          -- and updating those rows
     16          open c;
     17          loop
     18                  fetch c bulk collect into buffer limit 100;
     19
     20                  for i in 1..buffer.Count
     21                  loop
     22                          dbms_output.put_line(
     23                                  'row:'||i||
     24                                  ' id:'||buffer(i).foo_id
     25                          );
     26
     27                          update footab
     28                          set value = lower(value)
     29                          where foo_id = buffer(i).foo_id;
     30                  end loop;
     31
     32                  exit when c%NotFound;
     33          end loop;
     34          close c;
     35          commit;
     36  end;
     37  /
    
    Procedure created.
    
    // the contents of our table
    SQL> select * from footab;
    
        FOO_ID VALUE
    ---------- ------------------------------
             1 DUAL
             2 SYSTEM_PRIVILEGE_MAP
             3 TABLE_PRIVILEGE_MAP
             4 STMT_AUDIT_OPTION_MAP
             5 RE$NV_LIST
             6 STANDARD
             7 DBMS_STANDARD
             8 USER_REGISTRY
             9 ALL_REGISTRY_BANNERS
            10 V_$BH
    
    10 rows selected.
    
    // we lock and update row 5 - and we do not commit
    SQL> update footab set value='UPDATED' where foo_id = 5;
    
    1 row updated.
    
    // the other session's transaction runs, attempting to update all rows -
    // but skip any rows that are already lock (row 5 in this case)
    SQL> exec UpdateFoo
    row:1 id:1
    row:2 id:2
    row:3 id:3
    row:4 id:4
    row:5 id:6
    row:6 id:7
    row:7 id:8
    row:8 id:9
    row:9 id:10
    
    PL/SQL procedure successfully completed.
    
    // what can we see now in the test data?
    SQL> select * from footab;
    
        FOO_ID VALUE
    ---------- ------------------------------
             1 dual
             2 system_privilege_map
             3 table_privilege_map
             4 stmt_audit_option_map
             5 UPDATED
             6 standard
             7 dbms_standard
             8 user_registry
             9 all_registry_banners
            10 v_$bh
    
    10 rows selected.
    
    // we commit our transaction
    SQL> commit;
    
    Commit complete.
    
    // if the other session transaction runs now, it will find all rows
    // available for update
    SQL> exec UpdateFoo
    row:1 id:1
    row:2 id:2
    row:3 id:3
    row:4 id:4
    row:5 id:5
    row:6 id:6
    row:7 id:7
    row:8 id:8
    row:9 id:9
    row:10 id:10
    
    PL/SQL procedure successfully completed.
    
    // contents of the test data after its update
    SQL> select * from footab;
    
        FOO_ID VALUE
    ---------- ------------------------------
             1 dual
             2 system_privilege_map
             3 table_privilege_map
             4 stmt_audit_option_map
             5 updated
             6 standard
             7 dbms_standard
             8 user_registry
             9 all_registry_banners
            10 v_$bh
    
    10 rows selected.
    
    SQL> 
    
  • Awaiting invoice Interface - L.O. status line of incomplete data

    Hello!

    I created an RMA number using back to credit with receipt Workflow and after having received the amount in stock. The status of line become awaiting invoice Interface - incomplete data. I have read some material and he tells me that it is due to the Source of the invoice field in finance, tab Type of Transaction is not entered but my installation has this area. Still, what could be the source of this status?

    Thank you.

    Jon

    Just to clarify the above,

    (1) the Super user management responsibility order

    Navigation: Setup-> Types of Transaction-> define

    Click on the Finance tab, check if you have assigned a customer accounts

    type of transaction (this is also called the type of transaction (invoice))

    Please select a transaction type of customer accounts and keep.

    (2) claims responsibility

    Navigation: Setup-> transactions-> transaction types

    Questioning the "type of Transaction (invoice)" assigned to the step 1

    Check "Crédit mémo Type" is defined for this type of Transaction (invoice).

    If this isn't the case, you must define the type of credit for return lines and repeat step 1.

    This configuration is required.

    REDA

  • How to cancel the sales order - header and the status of the line at the point of entry

    Dear,

    I have a few sales order must be cancelled in which the header and the status of line are in * "entered." I'm not able to cancel these orders.

    Also note that these commands are for maintenance service. Once I have book these orders the lines will move to the closed state.
    Is it not possible to book and cancel the lines.

    To this problem me.

    Book order and then cancel it.
    :)

  • HP Officejet Pro 8610: hp Officejet Pro 8610 cannot send faxes "Fax line State Fail"

    Dear support,

    I would like to send and receive faxes from hp Office jet Pro 8610:

    -the phone system is on PABX

    -J' have installation eja prefix dial number is "9".

    -Fax, run the Test, he failed "Test status of line Fax".

    -J' removed the prefix number, still aren't.

    -Here are the pictures:

    -Here is the arpeggio

    I thnk there is no problem with the cord, it has passed the test.

    -When I dialed the number of fax to the recipient, the message 'no response '.

    -J' plugged the 2 - Ext on the phone port, it can be used to call (using the 9 prefix) and receive a call.

    Help, please

    It was caused by the digital telephone network. Fax it extreme requires analog network.

    solved by me.

    Thank you =)

  • How to view a newly created line only in adf table?

    Hi all

    JDEV 12.1.3.0

    When you drag move a VO on a page as a table of adf, it displays all the lines available in the whole of lines. I want to display only the rows that are newly created in the user interface.

    I achieved this goal by creating a transient "RowStatus" attribute, which will be the State of the entity (0-1 new, unmodified, 2 - modified) and I filtered the table using this status of line by double clicking on the VO and specified a filtered attribute and the value. But the performance is very poor, because I think it makes even all records and only newly created filter lines.

    Is there another way optimized to achieve?

    How to achieve this programmatically?

    If I run VO.executeEmptyRowSet () when the page loads, the table is rendered empty at first, but after call CreateInsert operation, all rows are returned with this new line.

    You see the same behavior if you create lines programmatically (with: vo.createRow (); vo.insertRow (row)) instead of CreateInsert?

    If it does not then only "programmatic" option is probably to set where clause 1 = 2

    Dario

  • Cancel a Fulfilled line

    Hello

    One of our users had created a command such as "Debit memo" (excluding shipping costs). The command line immediately in "Completed" status when the order is booked and then gets closed when the execution of the Workflow process. But due to an error of workflow, the line does not get closed and invoices has never been created. As the command line is very old, the user no longer has this line (which is cause errors in a system of declaration). But as the State of the line is 'filled' the user is not able to cancel the line that there is a constraint of treatment associated with cancel the line that prevents the line "Fulfilled" to cancel status. Temporary disabling of the treatment forced could cause problems as thousands of users use the system.
    Is there any API command process that does not take account of the constraint of the transformation (or any API that can be made to ignore the constraints of treatment) so that this line can be cancelled?

    Thank you
    Sikora

    Hi Sikora,
    Once the status of line gets fullfilled, we cannot change... it stays the same.

    Log an SR Oracle to get a datafix.

    Thank you
    -Arif.

  • hp7410 does not keep the wireless connection

    hp7410 all-in-one does not keep the wireless connection. It requires to install a new driwer. so far, I have at least 16 versions of the driver. neither maintains the status of line long enough fo more than a few hours.

    Please provide the following information if anyone can help including:

    The printer model - done

    Detailed problem description-

    Operating system on the computer (including the revision of the service pack)-

    Method - USB, LAN, Wireless cable connection? -

    Brand and model of router and modem? -

    Error messages - on the screen of the printer or computer, no matter what flashing light patterns.

    If wireless, status of the blue wireless light on the printer, active, disabled or flashing? -

  • BlackBerry calendar passport number

    When you create a calendar event, which goes over several days in the monthly graphic overview of calendar status, 'busy' line appears only in the first day of the event, the other days of the event are free. It's very confusing. You have the same problem?

    Hi @RobertP

    I was able to reproduce this problem, and it has connected with our development team. Updates, to bookmark this KB.

    KB36389 appointments that span several days are not properly presented in the monthly view

    Thank you!

  • BasicEditField the cursor with the wheel of trapping

    Hello

    I created a customized to handle the keypress TrackballClick and Enter BasicEditField.

    It works very well on blackberry with a trackball (latest), but the cursor is trapped in the field with Blackberry with a wheel (like the 8703e). As soon as it gets the focus, the cursor may not go out (or an upper field) or one of the below

    Here is the code:

    public class SearchInputField extends BasicEditField implements TrackwheelListener {
        ConnectionScreen parentScreen;
    
        public SearchInputField(String label, String initialValue, int maxNumChars, long style, ConnectionScreen screen) {
            super(label, initialValue, maxNumChars, style);
            this.parentScreen = screen;
        }
    
        public int getPreferredWidth() {
            return Display.getWidth() / 2;
        }
    
        public boolean keyChar(char key, int status, int time) {
          switch( key ) {
            case Characters.ENTER:
                parentScreen.PerformSearch();
                return true;
            }
            return super.keyChar(key, status, time);
        }
    
        public boolean trackwheelClick(int status, int line) {
            parentScreen.PerformSearch();
            return true;
        }
    
        public boolean trackwheelUnclick(int status, int line) {
            return true;
        }
    
        public boolean trackwheelRoll(int amount,int status, int line) {
            return true;
        }
    

    Any idea?

    Thank you

    No, he stayed in the first.

    In any case, fixed it by returning false in the method of the wheel (do not know why, but anyway... )

  • Impossible to detect that deployment of OS T630 SAS disks.

    I just bought the T630 and I'm having some trouble detection of hard disks during the deployment of the operating system. Any guidance would be greatly appreciated.

    The material is as follows:

    • Adapter H730 pole
    • Physical disks: x 2 SAS 300 GB; x 3 SAS 500 GB
    • Configuring RAID: RAID 1 (778 GB x 2) - designated for my OS (Win 2008 R2)
    • RAID 5 (465 GB x 3) - designated for the storage of data.

    I'm starting in the USB bootable flash drive BIOS mode (which works as I loaded the operating system on a test pc) and try to make the lifecycle controller operating system deployment.

    It comes after that Installer loads the files I can't see/detect the SAS drives in the configuration of the RAID above.
    I broke the mirror and re configured my virtual disk and initialized readers (Status: on line/loan), but are still unable to see them!

    I need a driver for the pole H730 controller so that the windows installation see the SAS drives? If yes how to deploy the drivers?

    Please notify.

    Kind regards

    DAXimusTT

    Yes, you do. Download and run to extract files, then put the files on a flash drive. When Windows finds no drives, click the drivers load and navigate to the location with the drivers.

  • How to install the language pack English on a Microsoft surface that is running Japanese Windows 8 RT?

    Hello
    I got a Microsoft Surface that is running Japanese Windows 8 RT. I need to change the system in English language. I downloaded English language pack (.cab file). I need to know hot to install it. Also, I can not install my dongle to the Surface. I t give an eror or something, so I can not accsess Internet to download the updated windows language pack.
    I also tried dism/Online/Add-Package/PACKAGEPATH:.cab command but it didn't work. This game me an error: 87 does not know the status in line/add_packegepath
    Please help me to solve this problem of tank you

    Hi Kishan,

    Please go through the steps mentioned in the link to add a language pack in Windows RT.

    http://Windows.Microsoft.com/en-in/Windows-8/language

    For more information: http://support.microsoft.com/kb/2607607/en-us?wa=wsignin1.0

    If you want to change the base language of Windows RT from Japanese to English, you need to reinstall the English version of Windows RT.

    Hope this information is useful. If you have any questions, please let us know.

  • How to upgrade are the value of the column and the new column value created

    Hi all

    create the table xxc_temp

    as

    Select donnees_1 'AB103', 'AAA' data_2 data_3 '123', 'RED' data_4, NULL status in all the double union

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3, data_4 'BLUE', NULL status in all the double union

    Select donnees_1 'AB106', 'CCC' data_2, '333' data_3, data_4 'BLUE', the double NULL status

    create the table xxc_base

    as

    Select donnees_1 'AB103', 'AAA' data_2, '123' data_3 data_4 'RED', 'Inactive' status of Union double all the

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3 data_4 'BLUE' status 'Active' of all the double union

    Select donnees_1 'AB106', 'CCC' data_2, '333' data_3, data_4 'BLUE', 'Inactive' status of double

    I need to update the status column xxc_temp with xxc_base value of the status column and also if the user tries to insert new values/lines in the xxc_temp

    So how can I update the status column? I mean automatically set to day and also new values/lines

    I need to update only that are Inactive then these lines should be updated in the temporary table

    We can do this by using the stored function, but I need to update the new status of lines also

    Please help me

    Here's another way to do it, using VIRTUAL function column as expression to get the status of the other table

    CREATE or REPLACE FUNCTION GET_STATUS (pDATA_1 IN TANK) RETURN VARCHAR2 DETERMINISTIC

    AS

    vstatus VARCHAR2 (8);

    BEGIN

    SELECT status in vstatus FROM xxc_base WHERE donnees_1 = pDATA_1;

    RETURN vstatus;

    END;

    /

    DROP TABLE 'XXC_TEMP ';

    CREATE TABLE 'XXC_TEMP '.

    ('DONNEES_1' CHAR (5),

    "DATA_2" TANK (3).

    "DATA_3" TANK (3).

    "DATA_4' VARCHAR2 (4).

    'STATUS' VARCHAR2 (8) GENERATED ALWAYS AS (SUBSTR (GET_STATUS (DATA_1), 1, 8)) VIRTUAL

    ) ;

    INSERT INTO 'XXC_TEMP' (data_3, donnees_1, data_2, data_4))

    Select "AB103' donnees_1, data_2 'AAA', '123' data_3, 'RED' data_4 of any double union

    Select donnees_1 'AB105', 'BBB' data_2, '222' data_3 data_4 'BLUE' of all the double union

    Select donnees_1 'AB106', 'CCC' data_2 data_3 '333', 'BLUE' double data_4);

  • WITH COUNT and GROUP BY

    I'm counting how many people have registered and COMPLETED a SPECIFIC set of units

    Must have completed all 2 units on the line

    Business - UNITS = ISR and DSW

    Physiology or medicine: UNITS = DFC and XFG

    Accounting - UNITS = DF and FGR

    1 ID enlisted in the operational units and two units of medicine so I would count this ID for each line

    ID 2 made only 1 of each line, so I won't count the ID. Want to only count who have completed all THE 2 units for each line

    ID3 enlisted in two business units then count

    4 ID was enrolled in two business units but fell on a count THAT as long as it isn't BOTH

    CREATE TABLE DAN_PATH
    (VARCHAR2 (12) ID,)
    UNIT VARCHAR2 (12),
    STATUS varchar2 (12),
    LINE VARCHAR2 (12));


    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'SRI', 'Registered ', ' BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'WA', 'Registered', 'ACCOUNTING');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'DSW', 'Registered ', ' BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'DFC', 'Registered', 'MEDICINE');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'XCV', ' registered', 'GENIUS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('1', 'XFG", 'Followed', 'MEDICINE');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('2', 'SRI', 'Registered ', ' BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('2', 'FD', ' registered', 'GENIUS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('2', 'FGR', 'Registered', 'ACCOUNTING');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('3', 'SRI', 'Registered ', ' BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('3', 'DSW', 'Registered ', ' BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('4', 'DF', 'Registered', 'ACCOUNTING');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('4', 'SRI', 'Coward', 'BUSINESS');
    insert into DAN_PATH (id, UNIT, STATUS, LINE) values ('4', 'DSW', 'Registered ', ' BUSINESS');

    GIVES:

    IDUNITSTATUSLINE
    1SRIRegistrantsCOMPANY
    1DRFDroppedACCOUNTING
    1DSWRegistrantsCOMPANY
    1DFCDroppedMEDICINE
    1XCVRegistrantsENGINEERING
    1XFGRegistrantsMEDICINE
    2SRIRegistrantsCOMPANY
    2FDSRegistrantsENGINEERING
    2FGRRegistrantsACCOUNTING
    3SRIRegistrantsCOMPANY
    3DSWRegistrantsCOMPANY
    4DFRegistrantsACCOUNTING
    4SRIDroppedCOMPANY
    4DSWRegistrantsCOMPANY

    I would like to get 2 queries that to me the line and the County of ID and the other to get me the ID

    LINESTUDENTS
    BUSINES2
    MEDICINE1
    ENGINEERING0
    ACCOUNTING0

    LINEID
    COMPANY1
    COMPANY3
    MEDICINE1

    Hello

    Let's start with 2 of the application; It's a little easier, and a solution for question 1 can be built on this subject:

    WITH units AS

    (

    SELECT 'SRI' AS Unit, 'BUSINESS' AS a dual UNION ALL

    SELECT 'DSW', 'BUSINESS' FROM dual UNION ALL

    SELECT 'DFC', 'MEDICINE' IN UNION double, ALL

    SELECT "XFG", 'MEDICINE' IN UNION double, ALL

    SELECT 'DF', 'ACCOUNTING' FROM dual UNION ALL

    SELECT 'FGR', 'ACCOUNTING' FROM dual UNION ALL

    SÉLECTIONNEZ « FUBAR », « GÉNIE » DE la double

    )

    SELECT u.line

    d.id

    U units

    JOIN dan_path d.unit d = u.unit

    AND d.line = u.line

    GROUP BY u.line

    d.id

    After HAVING COUNT (DISTINCT of CASE WHEN d.status = 'Registered' THEN d.unit END) = 2

    COUNT (CASE WHEN d.status = 'Loose' THEN d.unit END) = 0

    ORDER BY u.line

    d.id

    ;

    You can create a regular and permanent table for units, rather than use a WITH clause.

    You can get the results desired for the application 1 by a GROUP BY on the results of the query 2, with the exception of a few things.

    Quiz 1 must include all lines, even if no students not completed all units.  To get these numbers 0, we can do an OUTER JOIN.

    In addition, the HAVING of a query 2 clause eliminates the rows of the result set.  We do not want to eliminate lines that fail under these conditions, we just want to know if they do not arrive or not.  To do this, we have the same conditions inside a CASE, not a HAVING clause expression:

    WITH units AS

    (

    SELECT 'SRI' AS Unit, 'BUSINESS' AS a dual UNION ALL

    SELECT 'DSW', 'BUSINESS' FROM dual UNION ALL

    SELECT 'DFC', 'MEDICINE' IN UNION double, ALL

    SELECT "XFG", 'MEDICINE' IN UNION double, ALL

    SELECT 'DF', 'ACCOUNTING' FROM dual UNION ALL

    SELECT 'FGR', 'ACCOUNTING' FROM dual UNION ALL

    SÉLECTIONNEZ « FUBAR », « GÉNIE » DE la double

    )

    query_2_results AS

    (

    SELECT u.line

    d.id

    CASE

    WHEN COUNT (DISTINCT of CASE WHEN d.status = 'Registered' THEN d.unit END) = 2

    COUNT (CASE WHEN d.status = 'Loose' THEN d.unit END) = 0

    THEN 1

    END as finished

    U units

    LEFT OUTER JOIN dan_path d.unit d = u.unit

    AND d.line = u.line

    GROUP BY u.line

    d.id

    )

    SELECT line

    COUNTY (completed) as students

    OF query_2_results

    GROUP BY line

    ;

    I guess just some of your needs.

  • Need a Suggestion tune the SQL query

    Hello


    There is a view that is created that takes 17 seconds to run the query, when I split the query and run each query prend.15 seconds to run. Below the query I need to improve the performance of the code if you need your suggestion please order to tweek so this time take for execution to become less

    SELECT "Parature'"Source. "
    NULL 'retailer ',.
    reseller_name "reseller."
    NULL city "reseller."
    NULL state "reseller."
    A.Country "dealer Country."
    DECODE (a.state, "ACPA", "ACPA", 'EMEA', 'EMEA', NULL, 'Unknown', 'US') "Dealer Theater",
    NULL "Customer Name,"
    NO city 'customer ',.
    'Client state', NULL
    NULL 'country of the customer. "
    NULL "customer Theater."
    NULL "sales book Date."
    NULL "Ship Date."
    c.sales_order_number 'Sales Order Number',
    C.Po_Number "Number"
    controller_model_number_1 "product name."
    TRIM (UPPER (serial_number_1)) 'product serial number.
    c.contract_id "Contract ID",
    product_name 'name of support. "
    To_date (c.contract_purchase_date) "Start Date"
    To_date (c.contract_expiration_date) 'Expiry Date',
    NULL "header Status."
    NULL "status of line."
    NULL 'line Type. "
    NULL "reason for termination of employment."
    NULL 'location_id. "
    NULL 'Product_id '.
    Of edb_assets c,.
    edb_accounts one
    WHERE controller_model_number_1! = 'NULL '.
    AND Serial_Number_1! = 'NULL '.
    AND C.Amid = A.Amid (+)

    UNION
    SELECT "Parature'"Source. "
    NULL 'retailer ',.
    reseller_name "reseller."
    NULL city "reseller."
    NULL state "reseller."
    A.Country "dealer Country."
    DECODE (a.state, "ACPA", "ACPA", 'EMEA', 'EMEA', NULL, 'Unknown', 'US') "Dealer Theater",
    NULL "Customer Name,"
    NO city 'customer ',.
    'Client state', NULL
    NULL 'country of the customer. "
    NULL "customer Theater."
    NULL "sales book Date."
    NULL "Ship Date."
    c.sales_order_number 'Sales Order Number',
    C.Po_Number "Number"
    controller_model_number_2 "product name."
    TRIM (UPPER (serial_number_2)) 'product serial number.
    c.contract_id "Contract ID",
    product_name 'name of support. "
    To_date (c.contract_purchase_date) "Start Date"
    To_date (c.contract_expiration_date) 'Expiry Date',
    NULL "header Status."
    NULL "status of line."
    NULL 'line Type. "
    NULL "reason for termination of employment."
    NULL 'location_id. "
    NULL 'Product_id '.
    Of edb_assets c,.
    edb_accounts one
    WHERE controller_model_number_2! = 'NULL '.
    AND serial_number_2! = 'NULL '.
    AND C.Amid = A.Amid (+)
    UNION

    SELECT "Parature'"Source. "
    NULL 'retailer ',.
    reseller_name "reseller."
    NULL city "reseller."
    NULL state "reseller."
    A.Country "dealer Country."
    DECODE (a.state, "ACPA", "ACPA", 'EMEA', 'EMEA', NULL, 'Unknown', 'US') "Dealer Theater",
    NULL "Customer Name,"
    NO city 'customer ',.
    'Client state', NULL
    NULL 'country of the customer. "
    NULL "customer Theater."
    NULL "sales book Date."
    NULL "Ship Date."
    c.sales_order_number 'Sales Order Number',
    C.Po_Number "Number"
    controller_model_number_3 "product name."
    TRIM (UPPER (serial_number_3)) 'product serial number.
    c.contract_id "Contract ID",
    product_name 'name of support. "
    To_date (c.contract_purchase_date) "Start Date"
    To_date (c.contract_expiration_date) 'Expiry Date',
    NULL "header Status."
    NULL "status of line."
    NULL 'line Type. "
    NULL "reason for termination of employment."
    NULL 'location_id. "
    NULL 'Product_id '.
    Of edb_assets c,.
    edb_accounts one
    WHERE controller_model_number_3! = 'NULL '.
    AND serial_number_3! = 'NULL '.
    AND C.Amid = A.Amid (+)

    UNION
    SELECT "Parature'"Source. "
    NULL 'retailer ',.
    reseller_name "reseller."
    NULL city "reseller."
    NULL state "reseller."
    A.Country "dealer Country."
    DECODE (a.state, "ACPA", "ACPA", 'EMEA', 'EMEA', NULL, 'Unknown', 'US') "Dealer Theater",
    NULL "Customer Name,"
    NO city 'customer ',.
    'Client state', NULL
    NULL 'country of the customer. "
    NULL "customer Theater."
    NULL "sales book Date."
    NULL "Ship Date."
    c.sales_order_number 'Sales Order Number',
    C.Po_Number "Number"
    controller_model_number_4 "product name."
    TRIM (UPPER (serial_number_4)) 'product serial number.
    c.contract_id "Contract ID",
    product_name 'name of support. "
    To_date (c.contract_purchase_date) "Start Date"
    To_date (c.contract_expiration_date) 'Expiry Date',
    NULL "header Status."
    NULL "status of line."
    NULL 'line Type. "
    NULL "reason for termination of employment."
    NULL 'location_id. "
    NULL 'Product_id '.
    Of edb_assets c,.
    edb_accounts one
    WHERE controller_model_number_4! = 'NULL '.
    AND serial_number_4! = 'NULL '.
    AND C.Amid = A.Amid (+)

    UNION
    SELECT "Parature'"Source. "
    NULL 'retailer ',.
    reseller_name "reseller."
    NULL city "reseller."
    NULL state "reseller."
    A.Country "dealer Country."
    DECODE (a.state, "ACPA", "ACPA", 'EMEA', 'EMEA', NULL, 'Unknown', 'US') "Dealer Theater",
    NULL "Customer Name,"
    NO city 'customer ',.
    'Client state', NULL
    NULL 'country of the customer. "
    NULL "customer Theater."
    NULL "sales book Date."
    NULL "Ship Date."
    c.sales_order_number 'Sales Order Number',
    C.Po_Number "Number"
    controller_model_number_5 "product name."
    TRIM (UPPER (serial_number_5)) 'product serial number.
    c.contract_id "Contract ID",
    product_name 'name of support. "
    To_date (c.contract_purchase_date) "Start Date"
    To_date (c.contract_expiration_date) 'Expiry Date',
    NULL "header Status."
    NULL "status of line."
    NULL 'line Type. "
    NULL "reason for termination of employment."
    NULL 'location_id. "
    NULL 'Product_id '.
    Of edb_assets c,.
    edb_accounts one
    WHERE controller_model_number_5! = 'NULL '.
    AND serial_number_5! = 'NULL '.
    AND C.Amid = A.Amid (+)
    UNION
    SELECT "Source", "ERP"
    Imv.Bill_To 'retailer ',.
    Imv.Ship_To "dealer."
    Ship_To_City "Dealer City."
    Ship_To_State "State dealer."
    Edb2_Global.Country_Name_Theater (Imv.Ship_To_Country, 'COUNTRY') 'dealer country. "
    Edb2_Global.Country_Name_Theater (Imv.Ship_To_Country, 'THÉÂTRE') 'dealer Theater. "
    Cl.Company_Name "name of the customer."
    Cl.City "customer's city."
    Cl.State "State of the customer."
    Edb2_Global.Country_Name_Theater (cl.) Country, 'COUNTRY') 'country of the customer. "
    Edb2_Global.Country_Name_Theater (cl.) Country, 'THEATER') "customer Theater."
    Imv.So_Booked_Date "Date from the sale of book."
    Imv.Ship_Date "Delivery Date"
    Imv.Order_Number "client order number."
    Imv.Cust_Po_Number "Number"
    Cp.Item_Name "product name."
    Cp.Product_Serial_Number "serial number of product."
    To_char (Imv.contract_number) "Contract ID"
    Imv.Service_Description "name of support."
    Imv.Service_Start_Date "Start Date"
    Imv.Service_End_Date "expiration Date."
    Imv.Header_Status "header Status."
    Imv.Line_Status "status of line."
    Imv.Line_Type 'line Type. "
    Imv.Termination_Reason "reason for termination of employment."
    Cl.Location_Id 'location_id. "
    CP.ID "Product_id".
    Of ib_support_contracts_mv imv.
    customer_products cp,
    customer_locations cl
    WHERE superior (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number (+)))
    AND Cp.Location_Id = Cl.Location_Id (+)
    /


    There is a Union for each request, please suggest how tweek

    Thank you
    Sudhir

    A quick look indicates that first 5 select queries are that even accepting the 2 conditions

    WHERE controller_model_number_1! = 'NULL '.
    AND Serial_Number_1! = 'NULL '.

    Use SEPARATE and Clause OR reduce these 5 queries in one like that

    SELECT DISTINCT
               .....
               ......  
    
      FROM edb_assets       c
          ,edb_accounts     a
    WHERE  C.Amid = A.Amid(+)
      AND  (
              (     controller_model_number_1 != 'NULL'
                AND Serial_Number_1 != 'NULL'
              )
             OR
              (     controller_model_number_2 != 'NULL'
                AND Serial_Number_2 != 'NULL'
              )
             OR
              (     controller_model_number_3 != 'NULL'
                AND Serial_Number_3 != 'NULL'
              )
             OR
              (     controller_model_number_4 != 'NULL'
                AND Serial_Number_4 != 'NULL'
              )
             OR
              (     controller_model_number_5 != 'NULL'
                AND Serial_Number_5 != 'NULL'
              )
    
           )
    

    Concerning
    Arun

    Published by: Arun Kumar Gupta on May 9, 2012 12:10

Maybe you are looking for