Help - Tuning query based on the status column

Hello
I have a query in which I need to fetch records based on values in the status column. It can contain the values 'A' and 'P '. A record can have an "A" record and a record of 'P '. My conditions are,
(1) when it is only 'A' record, can return 'A' record.
(2) for the 'A' and 'P' folder is there, then return 'A' record.
(3) when 'P' registration is only, then return 'P' registration.
There are about 3 records 'A' Lake and 3K 'P '. I tried to use 'by' clause queries, but performance are too bad and I am not able to use it. When running as independent queries 'A' retrieval of documents is faster compared to the records of 'P '. When running in 'by' clause of the query is suspended. Please can anyone help how can be managed?

Due to restrictions, I won't be able to view the actual code. I post here a sample.

Example code:
WITH q1 AS
     (SELECT *
        FROM tab
       WHERE status = 'A'),
     q2 AS
     (SELECT *
        FROM tab
       WHERE status = 'P'),
     q3 AS
     (SELECT *
        FROM q1
      UNION ALL
      (SELECT *
         FROM q2
        WHERE NOT EXISTS (SELECT 1
                            FROM q1)))
SELECT *
  FROM q3
 WHERE ROWNUM < 501;
Thank you
Kadoch

One way is to use analytics like this:

SELECT *
FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY 
                                     ORDER BY t.status) rn
      FROM tab t
      WHERE t.status IN ('A', 'P'))
WHERE rn = 1

John

Tags: Database

Similar Questions

  • Different line colors based on the status of my order

    Hello

    I created a jspx page in my application. For the table, I want to display different color lines, based on the status of the order.

    When the State is new, I want to display in red. When the command is in progress, I want orange. approved in yellow, green and finished in grey for shipping.

    How can I achieve this?

    Thank you

    Hello

    Sorry, there was a typing error in my previous answer. You need to compare with 'In PROGRESS' and not 'INPROGRESS '.

    That is to say, the column should look like.

      <== Changed INPROGRESS to IN PROGRESS
    

    Arun-

  • IOM sql Query to get the status of the failed task

    Hello world

    We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.

    Thanks in advance.

    Kind regards
    MKN

    Hello
    Use this query to get the status of the task, also check the cooments

    SELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
    OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
    WHERE OSI.MIL_KEY = MIL.MIL_KEY
    AND ANN. 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 OUÉDRAOGO. USR_KEY = USR. USR_KEY
    AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
    AND OST. OBJ_KEY = OBJ. OBJ_KEY
    AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
    AND OBJ. OBJ_NAME = "User AD".
    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' - filter accordinglly Validation
    ;
    Thank you
    Kuldeep

  • Rows based on the timestamp column

    Hi Experts

    I'm trying to get the last 3 records based on the timestamp column. But I am not able to understand where I should start... ?

    To make it more clear

    I have the following data
    id date
    1  07/03/09 3:57:55.000000 PM
    2  08/03/09 9:23:55.000000 PM
    3  05/03/09 7:53:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    5  06/03/09 8:50:55.000000 PM
    I want to
    2  08/03/09 9:23:55.000000 PM
    4  08/03/09 5:41:55.000000 PM
    1  07/03/09 3:57:55.000000 PM
    Thanks and greetings
    Saurabh Sharma
    select *
      from (
    select *
      from x
     order by dt desc
     )
      where rownum <= 3
    

    Published by: Alex Nuijten on March 10, 2009 11:31

  • Need help query view with the 'Level' column name

    Hello world

    I use Oracle DB 10 g

    I have this request
    SELECT  count(per_id) 
    FROM    XXITS_EMP_MSTR_V
    WHERE   per_id = 213214 
    AND     Level='Technical Staff / Officer'
    XXITS_EMP_MSTR_V is a view created by someone else.

    I get the error "ORA-01788: CONNECT BY clause in this query block" for the the above statement.
    Is it possible that I can always get the result without changing the view?

    Any help is appreciated...

    Thank you
    Elmer

    Elmer says:
    Hello world

    I use Oracle DB 10 g

    I have this request

    SELECT  count(per_id)
    FROM    XXITS_EMP_MSTR_V
    WHERE   per_id = 213214
    AND     Level='Technical Staff / Officer'
    

    Place the level with quotes

    AND "Level" = 'Technical Staff / Officer'
    

    Make sure that the case is used correctly when using double quotes.

  • Query based on the partition of the date

    Hello

    I'm trying out only a professional successful integration in the last 24 hours of the day. If there is work that has the outcome of success and failure in the last
    24 hours for each day, I only managed the output. If there is no success for the same work, I pulled out as the last attempt at failed job.

    Here are my columns:
    current output:
     
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3400907     7/27/2012 10:01:09 AM     polA     target1          Failed          0     incr     clone1
    3389180     7/23/2012 10:01:14 AM     polA     target1          Failed          1     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3367074     7/22/2012 11:24:00 AM     polA     target1          Failed          1     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    336074     7/21/2012 10:01:08 AM     polA     target1          Success          0     incr     clone1
     
    desired output:
     
    JOB_ID     JOBDATE               GROUP     PATH          OUTCOME          FAILED     LEVEL     ASSET
    3400908     7/27/2012 10:01:18 AM     polA     target1          Success          0     incr     clone1
    3374713     7/23/2012 10:01:03 AM     polA     target1          Success          0     incr     clone1
    3374712     7/22/2012 11:24:32 AM     polA     target1          Success          0     Full     clone1
    3167074     7/21/2012 10:01:13 AM     polA     target1          Success          0     incr     clone1
    
    Here is a code I am trying to use without success:
    
    
    select *
     from
       (selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
              ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn 
                   from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
       where rn = 1
       order by jobdate desc;
    Thank you
    -Abe

    Hi, Abe,

    You are on the right track, using ROW_NUMBER to assign numbers and pick-up only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
    You want to assign a #1 for each distinct combination of group_id, path, assets and calendar day , right?
    Then, you need to PARTITION BY group_id, path, assets and calendar day . I think you understand that when you called this thread "query based * on partition date."

    The next thing is the controlling ORDER BY clause. To know which line of each partition is assigned #1, you must order the lines of result ("Success" first, then "Failed") and after that, of jobdate (jobdate last first, which is in descending order).

    If so, that's what you want:

    WITH     got_r_num     AS
    (
         SELECT  j.*     -- or list columns wanted
         ,     ROW_NUMBER () OVER ( PARTITION BY  group_id     -- GROUP is not a good column name
                                   ,                    path
                             ,             asset
                             ,             TRUNC (jobdate)
                                   ORDER BY          CASE  outcome
                                                 WHEN  'Succcess'
                                         THEN  1
                                         ELSE  2
                                             END
                             ,             jobdate     DESC
                           )      AS r_num
         FROM    job_table  j
         WHERE     outcome     IN ('Success', 'Failed')
    --     AND     ...     -- Any other filtering, if needed
    )
    SELECT     *       -- or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;
    

    If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test it.

    It seems that you posted several copies of this thread.  I bet that it's not your fault; This site can cause that.  Even if it's not your fault, please mark all versions duplicated this thread as "Answered" immediately and continue in this thread if necessary.

    Published by: Frank Kulash, 28 July 2012 23:47
    This site is crumbly than I thought! I saw at least 3 copies of this same thread earlier, but I'm not now.

  • Interactive report based on the hidden column cell color

    Hello

    APEX 5.0.1 used here.

    How can I set the color of a specific cell (or column) based on a hidden column?

    Seems the link that I can't use the built-in feature because I need the custom color returned by my request.

    I tried to set the color with javascript by iterate over each line, by taking the value. text() of the color column and value

    This color-specific cell. It works, but it requires the column is visible.

    A column containing a hexadecimal value of the color does not look good...

    I tried to hide / display: no column complete but this messes up the layout.

    THX

    the force says:

    APEX 5.0.1 used here.

    How can I set the color of a specific cell (or column) based on a hidden column?

    Seems the link that I can't use the built-in feature because I need the custom color returned by my request.

    I tried to set the color with javascript by iterate over each line, by taking the value. text() of the color column and value

    This color-specific cell. It works, but it requires the column is visible.

    A column containing a hexadecimal value of the color does not look good...

    I tried to hide / display: no column complete but this messes up the layout.

    Specify the color of cell required using the hidden column and a data attribute to the property Expression of HTML in the column:

    #VISIBLE_COLUMN_ALIAS#

    Apply a static ID of the visible column to serve as a selector, jQuery, and you can access the invisible color value in your JS code in dynamic action to run the JavaScript Code using the dataset property.

  • Delete based on the first column or column second row

    Dear members,

    Need to remove a MasterTable lines based on the value in an another RefTable (which is a subset of the main table) colA or ColB.

    / * Value refTable wedges designed to be
    create table RefTable (int num1, num2 int, int temp)

    Insert in the values of numbers (44445, 44444 11111)
    Insert in the values of numbers (44446, 44444 11111)
    Insert in the values of numbers (44447, 44444 11111)

    Insert in the values of numbers (55555, 55551, 11111)
    Insert in the values of numbers (55555, 55552, 11111)
    Insert in the values of numbers (55555, 55553, 11111)

    Insert in the values of numbers (22222, 22222 11111)
    Insert in the values of numbers (22222, 22222 11111)

    Suppose that MasterTable has given below
    create table MasterTable (int num1, num2 int, int temp)
    Insert in the values of numbers (22222, 22222 11111)
    Insert in the values of numbers (22222, 22222 11111)
    Insert in the values of numbers (22222, 22222 11111)

    Insert in the values of numbers (44444, 44444 11111)
    Insert in the values of numbers (44445, 44444 11111)
    Insert in the values of numbers (44446, 44444 11111)
    Insert in the values of numbers (44447, 44444 11111)

    Insert in the values of numbers (55555, 55551, 11111)
    Insert in the values of numbers (55555, 55552, 11111)
    Insert in the values of numbers (55555, 55553, 11111)
    Insert in the values of numbers (55555, 55554, 11111)

    insert into numbers values (4567, 12345, 11111)
    insert into numbers values (5678, 23456, 11111)

    The query should execute delete on MasterTable RefTable value-based to get the result that

    4567 11111-12345-
    5678 23456-11111.

    I tried to change the query something like
    delete of the MasterTable where num1 = any (select num1 of RefTable); but it can only manage the deletion of the colA part... Any suggestions
    Is this ?
    
    DELETE
    FROM
         MasterTable mt
    WHERE
         EXISTS
         (
              SELECT
                   1
              FROM
                   RefTable rt
              WHERE
                   rt.num1 = mt.num1
                     OR
                            rt.num2 = mt.num2
         )
     
    
  • Run one or the other query based on the result

    Hi all

    Is there anyway that I can design this query to run only a subquery based on the returned results.
    select to_char((NEXT_CHANGE# - 1),9999999999999999) latest_change 
    from v$archived_log 
    where SEQUENCE# =(select nvl(min(SEQUENCE#),0) 
                                   from v$archived_log 
                                   where ARCHIVED='YES' 
                                   and APPLIED='NO')
    
    If the above subquery returns 0, then I would like to execute the query below. Is there any way to embed multiple queries like case conditions ?
    
    select max(SEQUENCE#) 
                                   from v$archived_log 
                                   where ARCHIVED='YES' 
                                   and APPLIED='YES'
    Thank you

    G

    Edited by: USER101 December 9, 2010 09:34

    Hello
    Use the operator to decode your subquery:

    Select to_char ((NEXT_CHANGE #-1), 9999999999999999) latest_change
    v $ archived_log
    where SEQUENCE # = decode ((select nvl (min(SEQUENCE#), 0)))
    v $ archived_log
    When ARCHIVED = 'YES '.
    and APPLIED = 'NO'),
    0,
    (select max(SEQUENCE#)
    v $ archived_log
    When ARCHIVED = 'YES '.
    and APPLIED = 'YES'),
    (select nvl (min(SEQUENCE#), 0))
    v $ archived_log
    When ARCHIVED = 'YES '.
    and APPLIED = 'NO'));

  • IF NEW VARIABLE in SQL QUERY, DISPLAYS as the LAST COLUMN + rpad does not

    Hello all and thanks in advance.


    (1) if I add a new variable to my sql query to select a column, which was already on the table, it shows it in the report of the table as the last column on the right. In other words, if I add "the street" to

    something like city, postal code, street, store, Manager, etc., instead of placing the Street between CP and the Bank, the place like I said as the last column on the right.


    (2) when the values entered in the cells of the tables, Yes, they extend to their length, but, only if it is a Word. If it is two, as when I enter the value of 'very good '.

    then two lines as well as by a newline within the cell, for example, which in fact too high the rank. I tried sdap spaces with rpad but this did not work. something like rpad (stock, 20,' ')

    I have to say that the table is in the same page where there is a form, as the table grows in length it's actually squeezing the form on the left.


    (3) rpad did not work with the simpler syntax, but less would be with what I need, because it turns out that I am using DECODE to perform a conversion between the displayed value and

    value returned in my select list of values, something like: DECODE (TO_CHAR (stock), '1', 'Black', '2', 'Average', '3', 'good', '4', 'Very good', null) AS stock

    so, I tried to put the rpad there in several places, but either he gave the parse error or it has left empty do not pick up all the values in the column.


    Thank you very much

    Alvaro

    Alvaro

    (1) this is the standard behavior of the constructor of the apex. You can change the order of display with arrows in the report column attributes.

    (2) you have to play with the style of the column attributes to accomplice this. For the style of the instance = "" white-space: pre; ' in the attributes of the element column attributes. " White-space: normal would be put on several space (' ') 1. So no matter how you add with rpad, they will display as 1.
    Set a width or as attribute in a class style for this column.

    Nicolette

  • Hgrid amount format based on the currency column

    Hello

    I am trying to format columns hGrid based on the currency amount. I checked the old nets and tried, but it did not work. I do not know which API to use to get the item correctly format. All ideas are welcome.

    Thank you

    Alka

    Hi AlkaT,

    What exactly are you trying to achieve? you try to format a NUMBER type item in the currency of the system? If so the bottom of piece of code should work fine, just put in your controller processRequest() method:

    {} public processRequest Sub (pageContext OAPageContext, OAWebBean webBean)
    ...
    OAMessageStyledTextBean currencyField = (OAMessageStyledTextBean) webBean.findIndexedChildRecursive ("CurrencyFieldItem");
    currencyField.setAttributeValue (CURRENCY_CODE, "AUD"); / * Replace the currency of your country instead of AUD * /.
    ...
    }

    Concerning

    Brad

  • Help with query - Conversion of the value of the line to the value of the column for the same column

    CREATE TABLE TESTY
    (
      BATCH_ID  VARCHAR2(100 BYTE),
      LINE_NUM  NUMBER,
      STRING    VARCHAR2(100 BYTE),
      AMOUNT    NUMBER
    )
    /
    Insert into testy
       (BATCH_ID, LINE_NUM, STRING, AMOUNT)
     Values
       ('DBA', 1, '101-201', 100)
    /
    
    Insert into testy
       (BATCH_ID, LINE_NUM, STRING, AMOUNT)
     Values
       ('DBA', 1, '101-202', 200)
    /
    
    Insert into testy
       (BATCH_ID, LINE_NUM, STRING, AMOUNT)
     Values
       ('DEVELOPER', 2, '101-201', 110)
    
    /
    Insert into testy
       (BATCH_ID, LINE_NUM, STRING, AMOUNT)
     Values
       ('DEVELOPER', 2, '101-202', 210)
    /
    
    Insert into testy
       (BATCH_ID, LINE_NUM, STRING, AMOUNT)
     Values
       ('DEVELOPER', 2, '101-203', 310)
    /
    COMMIT
    /
    
    BATCH_ID     LINE_NUM     STRING     AMOUNT
    DBA          1          101-201     100
    DBA          1          101-202     200
    DEVELOPER     2          101-201     110
    DEVELOPER     2          101-202     210
    DEVELOPER     2          101-203     310
    
    Required Output 
    
    BATCH_ID     LINE_NUM  AMOUNT1 AMOUNT2
    DBA          1         100     200
    DEVELOPER    2         110     210
    Only need to this result for string IN (101-201', 101-202').

    Can anyone help. ?

    Thank you

    Hello

    In Oracle 8.1 or more

    SELECT       batch_id, line_num
    ,       SUM (CASE WHEN string = '101-201' THEN amount END)     AS amount1
    ,       SUM (CASE WHEN string = '101-202' THEN amount END)     AS amount2
    FROM       testy
    GROUP BY  batch_id, line_num
    ORDER BY  batch_id, line_num
    ;
    

    From Oracle 11.1, you can also use SELECT... PIVOT.
    For more information, see the FAQ forum {message identifier: = 9360005}

  • Help on query: how to produce from columns of ranks?

    Hi all
    I have a table table1 with below the structure and data
    Item     State          Value
    A1      MS          100
    A1      GOA          3
    A1      UP          4
    B2      MS          34
    B2      GOA          55
    B2      PB          3
    B2      DL          4
    B3      MS          99
    B3      TN          1
    I have a requirement to query this table and generate the output below
    Item      MS     GOA     UP     PB     DL     TN
    A1     100      3     4     0     0     0
    B2      34     55     0     3     4     0
    B3      99      0     0     0     0     1
    The problem here is that we can have multiple status codes, so as a result the query should return dynamically the number of columns

    Is it possible to produce above output? Any help will be appreciated.

    Oracle DB Version - Oracle 8i

    Thanks in advance!

    Hello

    This is called a pivot .
    The basic technique is something like:

    SELECT     item
    ,     SUM (CASE WHEN state = 'MS'  THEN value ELSE 0)     AS ms
    ,     SUM (CASE WHEN state = 'GOA' THEN value ELSE 0)     AS goa
    ,     SUM (CASE WHEN state = 'UP'  THEN value ELSE 0)     AS up
    ,     SUM (CASE WHEN state = 'PB'  THEN value ELSE 0)     AS pb
    ,     SUM (CASE WHEN state = 'DL'  THEN value ELSE 0)     AS dl
    ,     SUM (CASE WHEN state = 'TN'  THEN value ELSE 0)     AS tn
    FROM     table_x
    GROUP BY  item;
    

    but this requires you to know indicates how many there are, and what they are, when you write the query.

    Since you have not, you must run a preliminary motion that will generate a select like the one above, or at least SUM expressions for variable columns. This is called dynamic SQL code , and a technique to do this is included below. (The example uses COUNT, but any aggregate, including the SUM function, work).

    Another possibility is the aggregation of the chain, where instead of individual columns for each State, you have a huge column VARCHAR2, formatted to look like separate columns. The avaiable tools to do this in Oracle 8.1 are quite poor, however, so I think you're better with dynamic SQL.

    /*
    How to Pivot a Table with a Dynamic Number of Columns
    
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus.
    (This can be easily adapted to PL/SQL or other tools.)
    
    NOTE: Using SQL*Plus file I/O, as in this example, is just
    one of many ways to do dynamic SQL.
    */
    
    PROMPT     ==========  0. Basic Pivot  ==========
    
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    ;
    
    PROMPT     ==========  1. Dynamic Pivot  ==========
    
    --     *****  Start of dynamic_pivot.sql  *****
    
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    
    SPOOL     OFF
    
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    ;
    
    SPOOL     OFF
    
    --     *****  End of dynamic_pivot.sql  *****
    
    /*
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    
    */
    
  • Result of the query based on the form of the parameter

    Good morning people. I really couldn't come up with a smart enough subject line, but I'll try and make up the body.

    I currently have a report that accepts parameters on the parameter form. They are extra employees and Number of Copies. The employee ID is stored in the Employee table, but the number of copies is not.

    The output of the report shows all the different addresses and phone numbers, the employee a. lets say, Employee ID 0001 has two addresses - home and office. In the report of my request, he'll give me two records in the repeating group. However, I have another parameter and the ID of the employee who is the number of Copies. In this case, if the number of Copies to be printed is 1, so it isn't a problem. However, if the Number of Copies is entered by the user is 4, I think in this case 4 x 2 = 8 pages of report output (4 with the address of the House) and 4 with the address of the office.

    I know there is a way to do this using a temporary table in AfterPForm and then using the results of the query by joining my request to the temporary table, but I was really hoping to avoid this situation if it can be treated through the query.

    Main request:
    SELECT    e.emp_no,
              e.saln||e.first_name||' '||e.last_name emp_name,
              a.street,
              a.city||' '||a.province||' '||a.postal_code city,
              '('||a.tel_area||') '||a.tel_number telephone
    FROM      employee e, emp_address a
    WHERE     e.emp_no = a.emp_no
    AND       e.emp_no = :P_EMP_NO;
    Any help is appreciated. Thank you!

    Hello

    Since you started a new thread in the forum SQL and PL/SQL {message identifier: = 10470358}, please mark this thread as "Answered" right away.

  • Report, SQL query based on the values of the elements (question SQL)

    Hello

    I use APEX 4.0 with Oracle 10 g r2 under Windows XP Pro SP3.

    I have an interactive report and a menu with a few items to filter the report.

    It works with most of the elements, but my problem is to select lists that have additional values, for example:
    SELECT '(null)' display_value, 'NULL' return_value FROM DUAL
    UNION ALL
    select distinct(SPAT_AREA_NAME) display_value, SPAT_AREA_NAME return_value 
    from SPATIAL_POINTS
    order by 1
    and I will return null as ' (return '%').

    For example, if the user selects "(null)", the report should return all rows with a NULL value in the column AREA_NAME.
    If he chooses "", the report should return all the lines. "
    and if the user selects a value, the report should return all the lines containing the value in column AREA_NAME.

    I don't know how to build my application. I tried with the CASE statements, DECODE, etc... but I still can't!

    My report query is for now:
    select SPAT_ID,
     SPAT_ACCL_NAME,
     SPAT_AREA_NAME,
     SPAT_CLASS,
     SPAT_NUMBER,
     SPAT_PT,
     SPAT_TYPE,
     SPAT_STATUS,
    from SPATIAL_POINTS 
    where 
     upper(SPAT_AREA_NAME) LIKE upper(:P3_FILTRE_AREA_NAME)  AND
     upper(SPAT_ACCL_NAME) LIKE upper(:P3_FILTRE_ACC_NAME) AND
     upper(SPAT_CLASS) LIKE '%'||upper(:P3_SPATIAL_CLASS)||'%' AND
     instr(upper(:P3_SPATIAL_TYPE_VALUES),upper(SPAT_TYPE)) > 0 AND
     instr(upper(:P3_SPATIAL_STATUS_VALUES),upper(SPAT_STATUS)) > 0 AND
     instr(upper(:P3_SPATIAL_POINT_VALUES),upper(SPAT_PT)) > 0
    Any idea?

    Thank you!

    Yann.

    Hello

    Then, assuming that spat_accl_name is not a string value "NULL" then you can try this...

    SELECT spat_id,
           spat_accl_name,
           spat_area_name,
           spat_class,
           spat_number,
           spat_pt,
           spat_type,
           spat_status,
           ROUND(spat_cumul,
                 (SELECT up_number_precision
                  FROM   user_preferences
                  WHERE  UPPER(up_nice_login) = UPPER(v('APP_USER'))))
              AS "SPAT_CUMUL"
    FROM   spatial_points
    WHERE  :p3_filtre_acc_name IS NULL AND spat_accl_name IS NULL
           OR(CASE
                 WHEN :p3_filtre_acc_name = '%' THEN NVL(spat_accl_name,'NULL')
                 ELSE :p3_filtre_acc_name
              END = NVL(spat_accl_name, 'NULL'))
    

    See you soon

    Ben

Maybe you are looking for