Display Specific Values, Suppress others In SQL Query

Hi Everyone,
I am processing a donor report that displays certain status_codes
and suppresses those that do not meet the specified criteria.
mgt wants the specified codes to standout from the others especially with 100,000 donor records.
the specified codes are : 'UDAD' and 'DECD'.
CREATE TABLE DONOR(donor_id number(4), first varchar2(20),last Varchar2(20));
INSERT INTO DONOR(donor_id,first,last) VALUES(1111, 'John', 'Smith');
INSERT INTO DONOR(donor_id,first,last) VALUES(2222, 'Mary', 'Jane');
INSERT INTO DONOR(donor_id,first,last) VALUES(3333, 'Tom', 'Harris');
INSERT INTO DONOR(donor_id,first,last) VALUES(4444, 'Sandy', 'Lee');
CREATE TABLE DONOR_STATUS(donor_id number(4), status_code varchar2(4));
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(1111, 'UDAD');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(2222, '998');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(3333,'STMP');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(1111, 'SSS');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(2222, 'ECON');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(3333,'NFEX');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(1111, 'NCOA');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(2222, '995');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(3333,'DECD');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(4444,'UNEM');
INSERT INTO DONOR_STATUS(donor_id,status_code) VALUES(4444,'801');
the output should look like this :
STAT   DONOR_ID FIRST                LAST
UDAD       1111 John                 Smith
           2222 Mary                 Jane
DECD       3333 Tom                  Harris
           4444 Sandy                Leethis is the query I've written so far:
select distinct decode(s.status_code,'UDAD','UDAD','DECD','DECD',null) Statcode,d.donor_Id, first,last
from donor d, donor_status s
where s.donor_id(+)=d.donor_id order by d.donor_idwith this ouput:
STAT   DONOR_ID FIRST                LAST
UDAD       1111 John                 Smith
           1111 John                 Smith
           2222 Mary                 Jane
DECD       3333 Tom                  Harris
           3333 Tom                  Harris
           4444 Sandy                Lee
6 rows selected.it rolls up the non-criteria codes into one row with null value, then outputs the desired row with 'UDAD' or 'DECD' duplicating the output for those donors with the matching criteria code but who also have other non-criteria codes.
any tips/help greatly appreciated.

Hi,
Here's one way:
SELECT    STRAGG (s.status_code)     AS Statcode
,       d.donor_Id
,       d.first
,       d.last
FROM          donor          d
LEFT OUTER JOIN donor_status      s  ON   s.donor_id     = d.donor_id
                               AND     s.status_code     IN ('DECD', 'UDAD')
GROUP BY   d.donor_id, d.first, d.last
ORDER BY   d.donor_id
;You can't use OR or IN in an old-style outer join; that's why I used ANSI syntax.
Is it possible that the same donor would be both 'DECD' and 'UDAD'? What output would you want in that case?
If you have the user-defined aggregate funtion STRAGG, available from AskTom:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402
you could use STRAGG (s.status_code) instead of MIN (s.status_code), and get 'DECD,UDAD' when applicable.
Edited by: Frank Kulash on Jan 19, 2011 5:08 PM
Added STRAGG option

Similar Messages

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Showing column value as counter in sql query - report

    I created a classic report with search bar based on an sql query. I would like to show the "notes" column in this query using some sort of counter and as a hyperlink to another section on the page (same idea as footnotes in a book). So if I have 10 rows and 5 have "notes". I should show 1,2,3,4,5 in the notes column for those rows and the number gets displayed as a link to another section listing the notes 1 through 5.
    I was thinking of creating a hidden page item as the counter with value of 0 and then in my query doing counter+1 but i'm not sure how to do this or if i can do that...
    If anyone can help or have any other ideas I would really appreciate it!!
    Thanks,
    Hindy

    Well, I'm doing this in VB and the subquery is dynamic. I'm passing an ADO recordset to a routine that sets up a listview to display the results. The number of columns selected can vary. My idea was to size the columns appropriately based on the size of the data. Within the display routine I could:
    sql = "SELECT "
    for i = 0 to oRS.Fields.Count - 1
    sql = sql & "MAX(LENGTH(" & i & ")), "
    next 'i
    sql = sql & "FROM (" & oRS.Source & ")"

  • How can I display multiple column results of a sql query?

    I'm wanting to display the results of a query selecting from multiple columns, but I can't seem to find an item type that will allow this. I've tried LOV, multiselect, display as text and others. Any ideas on how to do this. Here is my basic query:
    Select ul.meaning,
    rqa.submission_date,
    rqa.location_num
    from
    cfa_rqa_doc_submit_dates rqa,
    cfa_user_lookups ul
    where
    rqa.location_num in (Select location_num from cfa_current_locations_mv
    where operator_person_id = :P1_PERSON_ID and substr(location_num,1,1) = '8')
    and
    ul.lookup_type_id='1269'
    and
    to_char(rqa.submission_date, 'month') = to_char(sysdate, 'month')
    and
    rqa.submission_date >= (SYSDATE-365)
    and ul.lookup_ID= rqa.document_type_id
    ;

    Hi,
    Do you just wish to display the result of the query? If so, you can simply parse it out in HTML.
    You can then choose if you want to use tables or css.
    Multiple column layout in tables are based on <tr> and <td>.
    <tr> is a table row, where <td> is a column.
    All tags should be closed.
    Example:
    <table>
    <tr>
    <td>col1</td><td>col2</td>
    </tr>
    <tr>
    <td colspan="2">spans over 2 cols</td>
    </tr>
    </table>If you want to do the same in css:
    (Seems this forum removes the styles!):
    float:left; width:50; << first div and 2 div (col 1 and col 2 style)
    float:left;clear:both; width:100%; << clear both, double width (spans over 2)
    <div>
    <div style="float:left; width:50;">col1</div><div style="float:left;width:50%;">col2</div>
    <div style="float:left;clear:both; width=100%;">Spans over 2 cols</div>
    </div>The div might look more complicated, but if you refrain from styling in the tags them selves, you can define different styles in the .css file.
    You need the clear:both to start a new line with the divs that float.
    I usually run a dedicated "new line" div, without content.. (exception beeing the html-entities version of ' ' (& nbsp ; << without the spaces)).
    eg.:
    <div style="cls"> </div>Parsing out the values from the PL SQL you do like so:
    begin
    declare
       cursor c_search is 
    Select ul.meaning,
    rqa.submission_date,
    rqa.location_num
    from
    cfa_rqa_doc_submit_dates rqa,
    cfa_user_lookups ul
    where
    rqa.location_num in (Select location_num from cfa_current_locations_mv
    where operator_person_id = :P1_PERSON_ID and substr(location_num,1,1) = '8')
    and
    ul.lookup_type_id='1269'
    and
    to_char(rqa.submission_date, 'month') = to_char(sysdate, 'month')
    and
    rqa.submission_date >= (SYSDATE-365)
    and ul.lookup_ID= rqa.document_type_id
    begin  
    htp.p('<div style="width:80%;">');
    for v_search in c_search loop
    htp.p('<div style="float:left;clear:none;">'||v_search.location_num||'</div>');
    htp.p('<div style="float:left;clear:none;">'||v_search.submission_date||'</div>');
    end loop;
    htp.p('</div>');
      end;
    end;Ps. hope I understood you correctly, also this code is untested.. but I hope it can still help.
    Edited by: Olav Alexander Mjelde on May 12, 2010 9:36 AM

  • Return value for Direct OBPM SQL Query in OBPM 10GR3

    Hi all,
    I use a direct SQL Query provided by OBPM 10GR3 in my automatic activity to select certain elements from the db. The query is as follows:-
    foreach (element in
    SELECT id FROM TESTTABLE WHERE requestId = 732 and status = 1 )
    // statements
    logMessage("-- The id is-->" +element.id);
    This only returns when the id is found in the db but returns nothing when not found in db?
    How can I always get a return value? atleast a true or false, so that I can put IF statements?
    Because if it returns nothing, the loop does not execute {}? So we cannot put something like:-
    foreach (element in
    SELECT id FROM TESTTABLE WHERE requestId = 732 and status = 1 )
    logMessage("-- The id is-->" +element.id);
    if(element.id == null)
    logMessage("-- Id Not Found -->" );
    else
    logMessage("-- Id Found -->");
    How can I always get a return value from my OBPM direct query ?
    Remember , I am not using DynamicSQL in this case?

    Hi,
    Set a Boolean flag value to False before the SQL query.
    Some thing like:
    boolean flag = false;
    foreach (element in
    SELECT id FROM TESTTABLE WHERE requestId = 732 and status = 1 )
    logMessage("-- The id is-->" +element.id);
    flag = true;
    if(flag) {
    logMessage("-- Id Found -->" );
    else
    logMessage("-- Id Not Found -->");
    Hope the above logic would work fine.
    Bibhu
    Edited by: Bibhuti Bhusan on Sep 2, 2011 11:48 AM

  • How to replace a table name with an item value in report region SQL query?

    I've got a SQL query in a report region that goes like this:
    SELECT :P30_HIDDEN FROM v_dms_dataset
    GROUP BY :P30_HIDDEN
    P30_HIDDEN is populated from a textfield input. Why doesn't this work, and is there a way to achieve what I'm trying to do here? I really need the ability to dynamically generate SQL queries in this way.

    Ben - you could either:
    1. case when :P30_HIDDEN = 'COL1' then col1 else ... end
    in order to determine which column to select (only really useful if you have a small number of predetermined columns to select from), or
    2. generate the SQL dynamically.
    Set the report region to SQL Query (PL/SQL function body returning SQL query), then have something like:
    declare
    l_sql VARCHAR2(4000);
    begin
    l_sql := 'SELECT ' || :P30_HIDDEN || ' FROM v_dms_dataset
    GROUP BY ' || :P30_HIDDEN;
    return l_sql;
    exception
    etc.
    end;
    John.

  • Putting a specific date range in an SQL query

    Hello team,
    I have a query that i have to run every month but still i have to extract information for a given time period.
    Please advise.

    SELECT gcard.ncrd as "CARD NUMBER",
    GPCSTMER.TFNAMCSU || ' ' || TNAMECSU "CUSTOMER NAME",
    TO_CHAR(GCARD.DISSUCRD,'DD-MM-YYYY') AS "FIRST ISSUE DATE",
    case when GCARD.CRSVLCRD = '000' then 'VALID '
    when GCARD.CRSVLCRD = '001' then 'LOST CARD '
    when GCARD.CRSVLCRD = '002' then 'STOLEN CARD '
    when GCARD.CRSVLCRD = '004' then 'FAULTY CARD '
    when GCARD.CRSVLCRD = '005' then 'RETURNED CARD '
    when GCARD.CRSVLCRD = '006' then 'STOP CARD '
    when GCARD.CRSVLCRD = '007' then 'SUBSTITUTED CARD '
    when GCARD.CRSVLCRD = '008' then 'CARD NOT ACTIVATED'
    end "CARD STATUS ",
    CASE
    WHEN Gaccount.CSTATACT = '000' THEN 'NORMAL '
    WHEN Gaccount.CSTATACT = '001' THEN 'GREYLIST '
    WHEN Gaccount.CSTATACT = '002' THEN 'CLOSED '
    WHEN Gaccount.CSTATACT = '003' THEN 'BLOCKED '
    END "ACCOUNT STATUS",
    TO_CHAR(GCARD.DEXPICRD,'DD-MM-YYYY') AS "EXPIRY DATE" ,
    case when GCARD.CUTYPCRD = '001' then 'PRIMARY '
         when GCARD.CUTYPCRD = '002' then 'AUTHORISED '
    end "ACC TYPE"      
    FROM GCARD,GACCOUNT,GRACTCRD,GPCSTMER
    WHERE GCARD.NCRD = GRACTCRD.NCRD AND
    GCARD.NBIN = GRACTCRD.NBIN AND
    GACCOUNT.NACT = GRACTCRD.NACT AND
    GACCOUNT.NBIN = GRACTCRD.NBIN AND
    GCARD.CRSVLCRD = 000 and
    Gaccount.CSTATACT = 000 and
    GPCSTMER.NCST = GCARD.NCST AND
    GCARD.NBIN IN (515869) AND
    PAN_INDEX_RANGE_ID = 50
    ORDER BY GCARD.DISSUCRD,gcard.ncrd,PAN_INDEX_RANGE_ID;
    This my whole query and when i extract the information i have for the whole range.. but me i want to input for a specific date range

  • How to default field values based on a sql query?

    I have a create form that has employee_id and supervisor_id fields. I am defaulting the employee_id based on the login info (no problem there). Now I want to default the supervisor_id also. Supervisor id is based on a sql query that takes the employee_id as a parameter for the where clause.
    How do I implement this in jDeveloper?

    I figured how to do this. I created a new EO, associated it to my base EO via association. Then put this code in the base EO's create() method:
    // Set supervisor id based on SupervisorEO
    SupervisorEOImpl supEO = getSupervisorEO();
    Number newSupId = supEO.getSupervisorId();
    setSupervisorId(newSupId);
    This seems to be the simplest.

  • Display specific value from List of Values(LOV)

    Hi All,
    Is this possible in BOXI R2 that i created a List of Values like below:
    1. P1AF
    2. P1XA
    3. P2AF
    4. P2XA
    5. P2XD
    6. P3AF
    7. P3XA
    8. P3XD
    and i would like to show only 1 & 2 values for specific users. Or switch on /off some values without accessing the database.

    Can you confirm that this question is posted to the correct forum, or if it should go into another? 
    If this is Universe Designer related, you can review your LOV's by:
    1. right-click on the object in the universe designer, and select Properties dialog
    2. Select Properties tab,
    3. Select 'Display'
    4. then shift or control select the LOV's that you want to be viewable,
    5. enable the checkmark next to 'Show Selected Only'
    6. Click OK, and then save and re-export the universe.

  • Legend needs to display Prompt values / Remove filters from chart query

    Hi
    I have 2 questions for the same chart so I hope it's OK to add them in one post.
    Firstly I have created a chart & added three Select List filters which work fine, the query is below, problem is that when I change back to '-ALL-' I get no data, it has filtered out all records as no data matches the value of '-ALL-' does anyone know the code to get around this?
    My chart query;
    select null link, P_MONTH AS MONTH, SUM(CALLS) AS data
    from DATA.MAIN_DATA
    WHERE WAREHOUSE = :P1_WAREHOUSE
    AND ANS_UNANS = :P1_ANS_UNANS
    AND PRODUCT = :P1_PRODUCT
    GROUP BY P_MONTH
    As I will have several queries like the one above for different options on the same chart, I would like the Legend to show what the user has chosen each time the options are changed ie;
    Something like the bolded text in the query to display the chosen values in the legend;
    select null link, P_MONTH AS MONTH, SUM(CALLS) AS *'P1_WAREHOUSE' || 'P1_ANS_UNANS' || 'P1_PRODUCT'*
    from DATA.MAIN_DATA
    WHERE WAREHOUSE = :P1_WAREHOUSE
    AND ANS_UNANS = :P1_ANS_UNANS
    AND PRODUCT = :P1_PRODUCT
    GROUP BY P_MONTH
    Any ideas/suggests?

    Woof777 wrote:
    Any ideas/suggests?Try the APEX forum ;)

  • How to display slected value in other list in apex?

    Hi All,
    I have created two select list
    1. Counrty
    2.State
    Based on the selection of country state wil lbe popluated, which i had implemneted using ajx process.
    Now i had created a button, on press of button again i will be dsiplaying second set of select lit items i.,e againg counrty and state.
    so what ever we selected from first select list..the same values should be populated in the second list items?
    How we achieve this?
    Thanks,
    Anoo..

    Hi All,
    Thanks, but may be my explanation is not celar i believe.
    Initally i have created 4 selects list items as
    1. Country
    2.State.
    3. Country1
    4.State1
    When the page loads i will be hiding the select list items ie. country1 and state1 will not be visibile on the screen, unless once click on button i will be displaying the
    country1 and state1.
    Now the data whcih we had selected in country and state nedds to be populated same data in country1 and state1 once i clicked on a button.
    How do we show this data when they clik on button.
    Thanks,
    Anoo..

  • Default value from another table - sql query

    I'm trying to make the default value of a text item as the result from an sql or pl/sql statement. I keep getting errors when I try to use a pl/sql statement to do this. Has anyone else done this?

    OK, here is what I tried to put in. I have a form and I wanted to add a text field that is derived from another table, such as:
    select question from qa_main where seq=:quest_num
    So, what I want is to have a form where questions on tests are answered, and I want the text of the question to be brought over from the question table. I'm not sure if I'm using the correct syntax, but the ":quest_num" would be a reference to a question number in the answer table that is linked to the sequence number (primary key) in the questions table.
    Of course if there are better ideas, please let me know. :)

  • Displaying filed value or other table filed in ALV output table

    Hi,
      I have a vendor leadger report displaying vendor balance statement witj all line item details,  all data is present in One final table  this final table i hvae shown in output but along with this  in the first line in output  i want to display openig balance of that vendor  and in the last line i want to display closing balance of that vendor in the period for opening balance and closing balabce i have that amount in the diffrent tables or fileds  how to display that amount in output along with my Final table .
    regards,
    zafar

    hi ,
        Do this way 
    1) get the opening balance  
    2)   append that line to final table
    3) then append data from other table in final table where data for all line item
    4) then again get closing balance
    5) append that data in final table and you will get first line as opening balance ,then middle data and last closing data .
    regards
    Deepak .

  • Get a insert session value for SQL query at report

    Hi friends
    I created a global temp table and procedure to support web search form.
    and a search result report. The procudure
    gets search result from multip tables and
    insert into temp table --recordsearch. I can get value from temp table  by call procedure
    at SQL*Plus.
    However, I can not get this value by web report.
    How can I get this insert session value and pass to SQL query for report?
    Thanks,
    Newweb
    CREATE GLOBAL TEMPORARY TABLE recordsearch
    (emp_id          VARCHAR2(200),
    ssn               VARCHAR2(9),
    fname          VARCHAR2(200),
    lname           VARCHAR2(200),
    m_name          VARCHAR2(200)
    ) ON COMMIT PRESERVE ROWS;

    it possible that your web form does not have a persistent, dedicated connection. if you have connection pooling for example, multiple sessions will see the same instance of the GTT, so if one deletes it, then nobody sees it (or you can see others data). if the connections are not persistent, then they can disconnect between calls, deleting the GTT table.

  • SQL Query returns values like "---" and "NA"

    Hi
              When I execute a sql query in MII it returns values like "---" and "NA" for empty Char and numeric fields respectively.
    I have checked the database and made sure that these fields does not have any value. This happens only when I run the query through MII. Can any one know how can we get rid of these values?
    Thanks in advance
    Shaji

    Shaji,
    MII sets those values as a default if it discovers null values in a query result. You can change this default behaviour in several ways.
    First, have a look at the document [Setting custom null values in XML|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/70628af0-8ec4-2c10-7da2-f451e412dd8f?quicklink=index&overridelayout=true]. Then you may also use SQL functions like [NVL|http://www.techonthenet.com/oracle/functions/nvl.php] to change the value directly in the SQL query. You can also change the value inside the MII BLT to whatever you need.
    Michael

Maybe you are looking for