cfinclude query: return the result to the specific line

I tried to crack this all day and I feel like if I just had a little nudge in the right direction I could succeed.

I have a query that returns records of some textbooks that are at a specific school. I standardized the database manuals so that the categories of primary, secondary and tertiary subjects are represented by the primary key of this category in its own table. The application loops through the records, I want to go back to the topic (varchar) category that goes with this (digital) key in the table.

Since Coldfusion will not allow nested cfoutput, I tried to use cfinclude to enter the specific name for the subject category that accompanies the current manual - but what I have until this returns all subjects for school in each row id - they are the subjects of law! but I'm not all, just the right with the good book/record one. Can anyone suggest what I need to do? I enclose the code for the home page and for one of the cfincludes (they are identical, except for the "primary", "secondary" and "tertiary").

I know I should leave something but I can't understand that. Thank you very much in advance.

Cow Holy, I managed to do work! Code attached... and thank you so much, everyone! * Phew *.

Tags: ColdFusion

Similar Questions

  • query returns different results depends on the length of the day

    Hello!

    I have a query:

    INSERT /*+ APPEND */ INTO pwa_process (
    id,
    id_session,
    id_customer,
    s2k_account,
    service_seq_num,
    msisdn,
    id_tariff,
    contract_end_date,
    last_contract_date,
    next_available_contract_date,
    tariff_name,
    description,
    description_long,
    imei_old,
    activation_date,
    id_customer_number,
    arpu,
    value0,
    value1,
    value2,
    value3,
    value4,
    value5,
    id_pricing_plan)
    WITH msisdns AS (SELECT msisdn ms FROM customer_number cn
    JOIN customer_s2kaccount cs ON cn.s2k_account = cs.s2k_account AND cs.id_customer = v_customerId)
    SELECT
    seq_pwa_process.NEXTVAL,
    v_sessionId,
    customer_s2kaccount.id_customer,
    customer_s2kaccount.s2k_account,
    customer_number.service_seq_num,
    msisdn.msisdn,
    tariff.id,
    NVL(CASE WHEN date_contract_end IS NULL AND le_contract_end_date IS NOT NULL OR (date_contract_end < le_contract_end_date)
             THEN le_contract_end_date
             ELSE NVL(date_contract_end, ADD_MONTHS(customer_number.date_start, customer_number.ada_availability))
        END, TO_DATE('01.01.1970', 'DD.MM.YYYY')) contract_end_date,
    CASE WHEN NOT customer_number.date_first_activation IS NULL AND customer_number.date_first_activation >      (CASE WHEN ada_priority = 1 THEN ada_date_pwa
            WHEN ada_priority <> 1 AND (date_pwa IS NULL AND exchange_date IS NOT NULL OR date_pwa < exchange_date) 
            THEN exchange_date 
            ELSE date_pwa 
      END) 
         THEN customer_number.date_first_activation
         ELSE   (CASE WHEN ada_priority = 1 THEN ada_date_pwa
            WHEN ada_priority <> 1 AND (date_pwa IS NULL AND exchange_date IS NOT NULL OR date_pwa < exchange_date) 
            THEN exchange_date 
            ELSE date_pwa 
      END) 
    END last_contract_date,
    ADD_MONTHS(CASE WHEN NOT customer_number.date_first_activation IS NULL AND customer_number.date_first_activation > NVL(  (CASE WHEN ada_priority = 1 THEN ada_date_pwa
            WHEN ada_priority <> 1 AND (date_pwa IS NULL AND exchange_date IS NOT NULL OR date_pwa < exchange_date) 
            THEN exchange_date 
            ELSE date_pwa 
      END) ,
                                                                                                                           NVL(customer_number.date_first_activation, NVL(customer_number.date_start, customer_number.date_effective)))
                    THEN customer_number.date_first_activation
                    ELSE NVL(  (CASE WHEN ada_priority = 1 THEN ada_date_pwa
            WHEN ada_priority <> 1 AND (date_pwa IS NULL AND exchange_date IS NOT NULL OR date_pwa < exchange_date) 
            THEN exchange_date 
            ELSE date_pwa 
      END) , NVL(customer_number.date_first_activation, NVL(customer_number.date_start, customer_number.date_effective)))
               END, customer_number.ada_availability - DECODE(NVL(customer_number.current_contract_type, 0), 2, DECODE(customer_number.reduced_contract_used, 0, NVL(customer_number.el_contract_calculated_reduc,0), 0), 0)) next_available_contract_date,
    tariff.name_ada,
    DECODE(msisdn_group.def_column, 0, msisdn.value0, 1, msisdn.value1, 2, msisdn.value2, 3, msisdn.value3, 4, msisdn.value4, 5, msisdn.value5, msisdn.value0),
    msisdn.value0 || ';' || NVL(msisdn.value1, '') || ';' || NVL(msisdn.value2,'') || ';' || NVL(msisdn.value3,'') || ';' || NVL(msisdn.value4, '') || ';' || NVL(msisdn.value5, ''),
    customer_number.imei,
    NVL(customer_number.date_first_activation, NVL(customer_number.date_start, customer_number.date_effective)) date_start,
    customer_number.id,
    NVL(s2kaccount.arpu1,0),
    msisdn.value0,
    msisdn.value1,
    msisdn.value2,
    msisdn.value3,
    msisdn.value4,
    msisdn.value5,
    customer_number.id_pricing_plan
    FROM customer_s2kaccount
    JOIN customer_number ON customer_number.s2k_account = customer_s2kaccount.s2k_account AND customer_number.service_state = 'AB'
    JOIN msisdn ON msisdn.msisdn = customer_number.msisdn
    JOIN TABLE(CAST(v_tmp_table AS ADA.NUMBER_TABLE)) ids ON ids.column_value = msisdn.id
    JOIN msisdn_group ON msisdn_group.id = msisdn.id_msisdn_group
    JOIN pricing_plan ON pricing_plan.id = customer_number.id_pricing_plan AND pricing_plan.is_for_pwa = 1
    JOIN tariff ON tariff.name = pricing_plan.id
    JOIN s2kaccount ON s2kaccount.s2k_account = customer_number.s2k_account
    LEFT
    JOIN (SELECT msisdn, exchange_date, ADD_MONTHS(exchange_date, MAX(prolongation)) le_contract_end_date
    FROM loyalty_exchange a, msisdns
    WHERE a.msisdn = msisdns.ms AND exchange_date >= ALL (SELECT exchange_date FROM loyalty_exchange b WHERE b.msisdn = a.msisdn)
    GROUP BY msisdn, exchange_date) le ON le.msisdn = customer_number.msisdn
    WHERE customer_s2kaccount.id_customer = v_customerId;
    This query returns different results in the morning (09:00) and afternoon (16:00) on the same database for the same input data (I have prepared a script to test).
    Oracle 9.2.0.6 @solaris
    I checked the query plans, but they look the same in the morning and the afternoon. I don't know where to look for a problem/bug.
    Please help me with suggestions. is in bug with join ansi? or a left outer join?

    Published by: batonoff on February 16, 2009 16:56

    Published by: batonoff on February 16, 2009 16:58

    Published by: batonoff on February 16, 2009 17:00

    I recommend you post your declaration in the {} code tags (without the spaces) so that we can actually read.

    You are absolutely positive that nothing has changed on the data between when you run in the morning and in the afternoon?

  • Select from another table, when the query returns no result

    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    Thank you.

    user10407139 wrote:
    Hello

    I have a question where I'm supposed to retrieve the address of an account id-based billing. However, the table of billing may not have an address. There is a table of addresses that always has an address for an account. If the billing address exists, it should be used, so I can't use the address table. Is it possible in a select statement to query to the billing address and if it does not exist, use the address table.

    SELECT * FROM accounts a, b billings WHERE a.accountid = b.accountid

    Any help will be greatly appreciated.

    I think you need to explain more clearly if

    -you only have a couple of "billing" columns which is empty and in this case, you want to use the columns from the table 'accounts '.

    - or you have a join with another table that doesn't return data, for example a foreign key "address_id" "billing" is zero and therefore the join to other tables 'address' will return all the data

    In the first case, you have already been provided with some examples here, how to use NVL or similar functions to achieve, even if the first post first evaluates the information of 'accounts' and if it is white using information from "billing". According to your description you need the other way around. The second post a subquery recursive useless in my opinion.

    In the latter case, you should probably use an "outer" join so that the data in your table "bills" are returned, even if the join to another table is not at all the lines.

    SELECT
    NVL(AD1.ADDRESS_ATTR1, AD2.ADDRESS_ATTR1) as ADDRESS_ATTR1,
    NVL(AD1.ADDRESS_ATTR2, AD2.ADDRESS_ATTR2) as ADDRESS_ATTR2,
    NVL(AD1.ADDRESS_STREET, AD2.ADDRESS_STREET) as ADDRESS_STREET,
    ...
    FROM accounts a
    INNER JOIN billings b
    ON a.accountid = b.accountid
    LEFT OUTER JOIN address ad1
    ON b.address_id = ad1.address_id
    INNER JOIN address ad2
    ON a.address_id = ad2.address_id;
    

    In this way you pick up the address stored in the "invoices" table, if it existed, otherwise you pick up the address assigned to the "accounts" table I used an inner for the second address join join because you said that the account always has an assigned address.

    Kind regards
    Randolf

    Oracle related blog stuff:
    http://Oracle-Randolf.blogspot.com/

    SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676 /.
    http://sourceforge.NET/projects/SQLT-pp/

  • sys_refcursor do not fetch any data, even if the query returns the value

    I use sys_refcursor to return the columns and aid below the procedure to do. Although the data are there in table_1 and table_2.

    PROCEDURE test_pro (abc_date N, DATE,
    cur_get_data ON sys_refcursor
    )

    OPEN cur_get_data
    for
    Select A.col1, B.col2
    from table_1 A
    where A.dis_date = abc_date
    left outer join
    table_2 B
    on
    A.dis_date = B.dis_date;

    IF cur_get_data % rowcount = 0
    then
    raise e_error;
    END if;

    EXCEPTION
    When e_error
    then
    -no_data_found;
    while others
    then
    -(giving an error with the SQL error code);

    END test_pro;


    When running under sql in the sql pl/sql developer window pick
    data
    Select A.col1, B.col2
    from table_1 A
    where A.dis_date = abc_date
    left outer join
    table_2 B
    on
    A.dis_date = B.dis_date;

    But while testing the test_pro in the test of the pl/sql Developer window, it is
    do not fetch all data and raise e_error every time

    is there a problem arising from the use IF cur_get_data % rowcount = 0 whenever that happens in the exception block.

    so can someone please put a few ideas what cud be the reason for this?
    PROCEDURE test_pro(abc_date IN DATE,
                       cur_get_data OUT sys_refcursor
                      ) is
    BEGIN
    
      OPEN cur_get_data for select A.col1,B.col2
                              from table_1 A
                             where A.dis_date = abc_date
                                   left outer join
                                   table_2 B
                                on A.dis_date = B.dis_date;
    
    /* while testing let exceptions just pop out
    EXCEPTION
    
      when no_data_found
      then
    ------no_data_found;
      when others
      then
    --------(giving SQL error with error code);
    */
    END test_pro;
    

    then you test as something like

    declare
    
      my_date   date := to_date('20120621','yyyymmdd');
      my_cursor sys_refcursor;
      col1      ... ;
      col2      ... ;
    
    begin
    
      test_pro(my_date,my_cursor);
    
      loop
    
        fetch my_cursor into col1,col2;
        exit when my_cursor%notfound;
        dbms_output.put_line(col1 || ' ~ ' || col2);
    
      end loop;
    
    end;
    

    Concerning

    Etbin

  • SQL query return different result 11 GR 1 material and GR 11, 2

    Problem: SQL returns different results in 11 GR 1 material and GR 11, 2 games.

    Example script:

    create the table tab_main
    (
    SOS number (2) not null,
    contract number (2) null
    )
    /

    create the table tab_sub
    (
    number (2) of contract non-null,.
    SOS number (2) null
    )
    /

    insert into tab_main values (1, 10);
    insert into tab_main values (2, 20);
    insert into tab_main values (3, null);
    insert into tab_main values (4, null);

    insert into tab_sub values (1, 10);
    insert into tab_sub (20, 2) values;
    commit;

    The SQL code:

    SELECT *.
    OF tab_main.
    tab_sub
    WHERE tab_main.sos = tab_sub.sos (+) AND
    tab_main. Contract = tab_sub.contract (+) and
    tab_main. Contract not in (select 1 of the double);

    The above query gives more results
    -by 11.2.0.4
    1 10 10 1
    2 20 20 2

    -in 11.1.0.7
    1 10 10 1
    2 20 20 2
    4
    3


    Please tell us what could be the reason for the behaviour of offset lines thie.


    Thank you

    Piesset

    I think it is probably a bug in 11.1.0.7 (and possibly other versions), I get the same results as your 11.2.0.4 9.2.0.7, 10.2.0.3 and 11.2.0.3, and this is the result, I expect.

    Your not in the paragraph is equivalent to:

    SELECT *.

    OF tab_main, tab_sub

    WHERE tab_main.sos = tab_sub.sos (+) AND

    tab_main. Contract = tab_sub.contract (+) and

    tab_main. Contract <> 1;

    Since you have null values in tab_main.contract they are lost by the predicate since null = value is never true (or false).

    John

  • Select the query with the level line list where the clause

    Hi all

    I am creating a tabular presentation based on a SQL query that has a list of selection based on a query with a where clause clause that refers to a column in the original SQL query.

    The situation is, I have a table that stores the client_id, source_id, and build_id, lets call it client_source. I have a second table, build_source, containing source_id and build_id, one to many relations between the two (1 source_id could have build_id 1-7).

    Using a tabular presentation, I want to select the correspondent build_id to use in client_source, but the selection list should contain only the build_id for this particular source_id of lines.

    Here is an example of the SQL source of tabular presentation;

    Select
    s.ROWID,
    s.CLIENT_ID,
    s.SOURCE_ID,
    APEX_ITEM. SELECT_LIST_FROM_QUERY (1, s.BUILD_ID,)
    "Select display b.build_id, b.build_id return.
    b build_source where b.source_id = s.SOURCE_ID ') lst
    of s client_source

    what I want to achieve, it's as source_id "BOLD" match fields. When the query is built this way, I get an error of "invalid identifier" Oracle on s.SOURCE_ID during execution.

    Is there some special tags to be used to refer to the external column? I must be missing something because this looks like a pretty mundane problem.

    I am running on 4.1.0.00.32, on an Oracle 10 g release 10.2.0.4.0 Server Express request.


    I look forward to useful responses!


    See you soon,.
    Jason

    Published by: 1005131 on May 9, 2013 19:02

    Your selection by query list receives a static SQL. That SQL can't "see" the value of your s.source_id.
    But it would work like this:
    where b.source_id = ' | s.SOURCE_ID)

    You would be the value for the SQL concatenation. It is not ideal, but it will work.

    Jorge

  • FIRST analytical functions returns the null line

    The following query returns a null line when there is no such thing as a line for the predicate. Is it a bug or expected behaviour. If so what is the meaning of the null row, is it not logical?



    SELECT NVL (max (ah.fyr_end_dt) KEEP (DENSE_RANK FIRST ORDER BY ah.as_of_dt DESC), ' RETURNED NULL')
    Of account_history ah
    WHERE
    Ah.acct_id = 999
    AND trunc (ah.as_of_dt) < = 31 December 08 '
    ;

    Hello

    user4900730 wrote:
    Moreover, in my example how I distinguish the case where a line really exists, but the column is null when there is no such thing as a line and the FIRST function returns the same value null? Hopefullly I should be able to do it in a single SQL and know the difference?

    COUNT (*) > 0, but COUNT (col_x) = 0, then there is a line, but col_x happened to be null.

    For example, the following query shows that there is 1 row in the group with the lowest name ("ADAMS"), but the column comm in all ranks of this group is null:

    SELECT     COUNT (*)    KEEP (DENSE_RANK FIRST ORDER BY ename)
                              AS total_cnt
    ,     COUNT (comm) KEEP (DENSE_RANK FIRST ORDER BY ename)
                              AS comm_cnt
    FROM     scott.emp
    ;
    

    Output:

     TOTAL_CNT   COMM_CNT
    ---------- ----------
             1          0
    

    The employee whose highest name ("WARD") has a number in the comm column.

  • OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0

    I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).

    The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.

    I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).

    This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.

    Here is the code:

    Login: SYS as SYSDBA or SYSTEM (same results for either)

    SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
    OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
    WHERE
    M.OWNER = 'ML' AND
    T.OWNER = 'TUT';

    Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.

    Any thoughts?

    Hello

    If you read what I posted, forget it. MScallion (below) gave the correct answerr.

    If conditions such as

    owner   = 'ML'
    

    in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.

    The inner join returns only 131 lines where the two 'paintings' have the same table_names.
    The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.

    Published by: Frank Kulash, July 10, 2010 14:23

  • Unable to display the entire contents of the CF query return the result on my Web see page

    Hello

    I'm trying to extract data from a table (project_reports), which is to have a column of type CLOB (details) inside data.

    Details this column takes a huge amount of data in it.

    And I use the code to retrieve and display the data on my CF Web page below.


    < cfquery name = "getReport" datasource = "myDS" >
    Select details in project_reports where project = 54516
    < / cfquery >

    < cfoutput query = "getReport" > #getReport.details # < / cfoutput >


    ColdFusion is able to process and display a quantity limited data, but not the full data.
    I want to retrieve and display all of the data using ColdFusion.
    Can someone help me on this? Thanks in advance.

    Kind regards
    Jacques.

    Mamidela wrote:

    ColdFusion is able to treat & display a quantity limited data, but not the full data.

    Check the data source settings in the CF administrator. Make sure that the CLOB parameter (enable Long Text Retrieval) is checked.  When this box is _not_ checked, CF retrieves only the 64000 bytes.

  • Parameter query returns no results

    Hello

    I need a parameter query to return all customers for the locality.

    The name of the locality is given as a parameter.

    The problem with me is that the query is not even a single line when it should return at least fifty!. Locality is not unique, and there are a lot of consumers with the same value for the LOCALITY. The query I use is given below:

    SELECT ROWID, of GEOM FROM NOT_MY_CONSUMERS WHERE'= a ' and LOCALITY =: var1;

    When I try to use an ObjectID as parameter the result is returned property. ObjectID is unique for each line and thus a single row is returned
    in the result.

    Is it not possible to use the parameter query for non-unique settings?

    Help, please!
    I'm stuck with my project.

    Thank you very much!!

    Neha

    Published by: Neha39 on March 16, 2012 04:53

    Published by: Neha39 on March 16, 2012 05:15

    As your column data type, please use this one:

    SELECT ROWID, of GEOM FROM NOT_MY_CONSUMERS WHERE'= a ' and trim (TOWN) =: var1;

  • Database query returns no results

    Hello

    I timesten arrangement with Oracle as backend, the passthroughlevel is set to 1, which means that if the table is not found in timesten then go to Oracle, but I am facing a problem when querying for what anyone using ttIsql, there is no return line, although when I run the same query in Oracle directely I get the desired result.

    Here is the operation made by me:

    Command > connect myOraCache
    Successful login: DSN = myOraCache; UID = EIT; DataStore = / usr/ptyagi/timesten/datastore/ietds; DatabaseCharacterSet = WE8ISO8859P1; ConnectionCharacterSet=US7ASCII;DurableCommits=1;DRIVER=/usr/iris/timesten/TimesTen/tt70/lib/libtten.so;OracleId=iet
    ; Authenticate = 0; PermSize = 400; PassThrough = 1; TypeMode = 0;
    (Default AutoCommit = 1).
    Command > select * from category WHERE = iris_codes "side."
    0 rows found.

    Pramod salvation,

    There is no space or time here for a full tutorial on TimesTen Cache Connect; You should study the documentation TimesTen Cache to better understand how it works.

    Briefly...

    A cache group TimesTen is an SQL object that defines one or more tables that will be cached to Oracle, as well as the relationship of foreign key between them. Foreign key relationships defined in Oracle generally will also be defined in TimesTen if there may be exceptions to this rule.

    Cache group definitions can be created in TimesTen via SQL (usually by taking a copy of the schema creation script Oracle and editiing it) or through the interface of Administration of Cache TimesTen.

    However, the first step is to decide which tables you want to cache and why. The goal of caching is to improve performance for the application key functions. Although it is sometimes possible to cache all tables in Oracle, it is often not practical and not desirable (for example, it may need too much memory for TimesTen).

    I would say that yiu address the issue as follows:

    1 study the documentation for cache TimesTen understand how TimesTen caching works, the different types of cache groups and their functionality (and limitations)

    2. If looks help TimesTen as a cache may be feasible for you, perform some simple tests for key areas see what level of performance improvement you get by doing TimesTen. This can be very variable, a well-written application that is well suited to caching can see huge improvements while an application that is not well suited to caching or which is poorly implemented may see little or no improvement.

    3. If after these two steps, it is clear TimesTen will provide you a significant bnefist then you will be in a good position to decide how best to implement TimesTen for your application.

    It is important to understand that TimesTen is almost never just a kind of "Plug and performance is much better" solution. Detailed thought and planning must be done from the outset in order to achieve the best of TimesTen.

    Chris

  • SQL to return the first line

    Hello guys,.

    I use a sql to sort a single column of a specific sort order, I need just the first returned row based on ID (doc_no) here is an example:
    SQL> WITH 
      2  table_a AS (
      3  SELECT 1 doc_no, 'Description of 1' doc_desc FROM DUAL UNION ALL
      4  SELECT 2, 'Description of 2' FROM DUAL),
      5  table_b AS (
      6  SELECT 1 fk_doc_no, 'A' client_rev, TO_DATE ('10/10/2008', 'dd/mm/yyyy') due_date, 
      7   TO_DATE ('10/10/2008', 'dd/mm/yyyy') trans_date FROM DUAL UNION ALL
      8  SELECT 1, 'B', TO_DATE ('05/11/2008', 'dd/mm/yyyy'), TO_DATE ('05/11/2008', 'dd/mm/yyyy') FROM DUAL UNION ALL
      9  SELECT 1, '0', NULL, TO_DATE ('21/11/2008', 'dd/mm/yyyy') FROM DUAL UNION ALL
     10  SELECT 2, 'A', TO_DATE ('25/11/2008', 'dd/mm/yyyy'), TO_DATE ('25/11/2008', 'dd/mm/yyyy') FROM DUAL UNION ALL
     11  SELECT 2, '0', NULL, TO_DATE ('25/11/2008', 'dd/mm/yyyy') FROM DUAL)
     12  SELECT x.doc_no, x.doc_desc, y.last_client_rev, y.due_date, y.trans_date
     13  FROM (SELECT   fk_doc_no,
     14                 MAX (client_rev) KEEP
     15                   (DENSE_RANK LAST ORDER BY TRANSLATE(client_rev
     16                                                       ,'ABCD012' -- Desired sort order
     17                                                       ,'012ABCD' -- Actual sort order
     18                                                      )) AS last_client_rev,
     19                 due_date, trans_date
     20            FROM table_b
     21        GROUP BY fk_doc_no, due_date, trans_date) y,
     22       table_a x
     23  WHERE x.doc_no = y.fk_doc_no;
    The result is:
        DOC_NO DOC_DESC         L DUE_DATE TRANS_DA
    ---------- ---------------- - -------- --------
             1 Description of 1 0          21/11/08
             1 Description of 1 A 10/10/08 10/10/08
             1 Description of 1 B 05/11/08 05/11/08
             2 Description of 2 0          25/11/08
             2 Description of 2 A 25/11/08 25/11/08
    The required data will be:
        DOC_NO DOC_DESC         L DUE_DATE TRANS_DA
    ---------- ---------------- - -------- --------
             1 Description of 1 0          21/11/08
             2 Description of 2 0          25/11/08
    Can you help me with this?

    Best regards.
    BTW: I use Oracle 10 g

    Hello
    You don't need a subquery

    SELECT   fk_doc_no, doc_desc,
             MAX (client_rev)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
                                                  (client_rev,
                                                   'ABCD012' -- Desired sort order
                                                            ,
                                                   '012ABCD'  -- Actual sort order
                                                  )) AS last_client_rev,
             MAX (due_date)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
                                                  (client_rev,
                                                   'ABCD012' -- Desired sort order
                                                            ,
                                                   '012ABCD'  -- Actual sort order
                                                  ),
              trans_date) due_date,
             MAX (trans_date)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
                                                  (client_rev,
                                                   'ABCD012' -- Desired sort order
                                                            ,
                                                   '012ABCD'  -- Actual sort order
                                                  )) trans_date
        FROM table_a x, table_b y
       WHERE x.doc_no = y.fk_doc_no
    GROUP BY y.fk_doc_no, doc_desc
    
    SQL> WITH table_a AS
      2       (SELECT 1 doc_no, 'Description of 1' doc_desc
      3          FROM DUAL
      4        UNION ALL
      5        SELECT 2, 'Description of 2'
      6          FROM DUAL),
      7       table_b AS
      8       (SELECT 1 fk_doc_no, 'A' client_rev,
      9               TO_DATE ('10/10/2008', 'dd/mm/yyyy') due_date,
     10               TO_DATE ('10/10/2008', 'dd/mm/yyyy') trans_date
     11          FROM DUAL
     12        UNION ALL
     13        SELECT 1, 'B', TO_DATE ('05/11/2008', 'dd/mm/yyyy'),
     14               TO_DATE ('05/11/2008', 'dd/mm/yyyy')
     15          FROM DUAL
     16        UNION ALL
     17        SELECT 1, '0', NULL, TO_DATE ('21/11/2008', 'dd/mm/yyyy')
     18          FROM DUAL
     19        UNION ALL
     20        SELECT 2, 'A', TO_DATE ('25/11/2008', 'dd/mm/yyyy'),
     21               TO_DATE ('25/11/2008', 'dd/mm/yyyy')
     22          FROM DUAL
     23        UNION ALL
     24        SELECT 2, '0', NULL, TO_DATE ('25/11/2008', 'dd/mm/yyyy')
     25          FROM DUAL)
     26  SELECT   fk_doc_no, doc_desc,
     27           MAX (client_rev)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
     28                                                (client_rev,
     29                                                 'ABCD012' -- Desired sort order
     30                                                          ,
     31                                                 '012ABCD'  -- Actual sort order
     32                                                )) AS last_client_rev,
     33           MAX (due_date)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
     34                                                (client_rev,
     35                                                 'ABCD012' -- Desired sort order
     36                                                          ,
     37                                                 '012ABCD'  -- Actual sort order
     38                                                ),
     39            trans_date) due_date,
     40           MAX (trans_date)KEEP (DENSE_RANK LAST ORDER BY TRANSLATE
     41                                                (client_rev,
     42                                                 'ABCD012' -- Desired sort order
     43                                                          ,
     44                                                 '012ABCD'  -- Actual sort order
     45                                                )) trans_date
     46      FROM table_a x, table_b y
     47     WHERE x.doc_no = y.fk_doc_no
     48  GROUP BY y.fk_doc_no, doc_desc
     49  /
    
     FK_DOC_NO DOC_DESC         L DUE_DATE   TRANS_DATE
    ---------- ---------------- - ---------- ----------
             1 Description of 1 0            2008-11-21
             2 Description of 2 0            2008-11-25
    
    SQL> 
    

    Published by: Salim champion 2009-01-26 06:47

  • 12.2.4 WebADI - Integrator custom fails to cleanup script is triggered when the import returns the error lines

    Hi, hoping for help because it is not very useful detailed documentation on this topic here.

    I built a custom WebADI that uses custom procedures to validate and download the date in a custom table.  I then called an importer script that checks the balance of files (and other things) and mark the lines that do not reach a State of error.  I also managed to get these errors to be selected by the definition of error line and message error search section and everything is right with the world.

    Except that when imported and reports to hide the sad faces appear in the worksheet, I expect the cleanup script then learn to delete the records so that when the errors are corrected in the spreadsheet we don't get the lines in double... and is not.  No amount of tweaking, etc. application errors will result in cleaning the fire.

    Can someone tell me what I need to import of PL/SQL program to do when it detects a mistake for execution of the cleaning procedure?

    Thanks in advance

    Mike

    IT FIXED myself.

    The downloaded must be a function and return an error message of VARCHAR2.  If you return NULL - then the cleaning is not called as expected. If you return to any string, then cleanup is called.

  • Return the first line with a non-null value in a column

    Hey there, gurus. Can someone give me a hand with this?

    I have a table with six columns: Class_ID, Course_ID, start_date, Last_Name, First_Name, company. When our students take a class and will fill in an evaluation form, they fill in the Class_ID Last_Name First_Name, and Company. The Course_ID and Start_Date are filled automatically based on the Class_ID.

    I am trying to generate a report that contains Class_ID, Course_ID and Start_Date, PLUS the value of the first not null in the column of company for a combination given to the three first columns. Here is my SQL that does not quite do the trick:

    Select distinct c.class_id, c.course_id, c.start_date, p.company
    class c, person p, student s
    where substr (c.course_id, 1, 3) = "OBI".
    and c.start_date > = SYSDATE-30
    and c.class_id = s.class_id
    and s.pid = p.pid
    order start_date, company, class_id, course_id

    At present, if in a given class, a student entered "CCCC" under the name of the company and another entry "Collin Co Comm Coll" and another between "Collin College", I would get three rows of this class when you use the SQL above. I want just one line. I don't really like which company names gets selected - one of them will be great for our needs. I just need to see a line for each class_id and single value that some students entered the area of the company. And I guess I have to say that if no student fills in the name of the company I need to see the value null, because I need to see the line no matter what.

    Looks like some sort of funky outer join or a coalesce, but it is beyond my ability to understand.

    Now I get this:
    During class 1234 SQL271 Date 22/07/2013 company XYZ Inc.
    Made up of class 1234 SQL271 Date 22/07/2013 company XYZ
    1234 SQL271 Date 22/07/2013 company XYZ, class

    What I want:
    Class 1234 SQL271 22/07/2013 Date course XYZ Inc. or one of the other 2

    Thanks in advance!
    select c.class_id, c.course_id, c.start_date, max(p.company) company
    from class c, person p, student s
    where substr(c.course_id,1,3) = 'OBI'
    and c.start_date >= SYSDATE-30
    and c.class_id = s.class_id
    and s.pid = p.pid
    group by c.class_id, c.course_id, c.start_date
    order by class_id, start_date, course_id
    

    Or if you want to list all businesses, you can use LISTAGG if you're on the latest version of ORACLE

  • Need to return the duplicate lines

    Hello

    I have two data different sets as below:

    SERIES 1:
    col1 col2 col3
    2 cust1 NULL
    3 cust2 NULL
    1 cust NULL
    1 cust NULL

    SERIES 2:
    col1 col2 col3
    1 prod NULL
    1 prod NULL
    2 NULL prod1
    3 NULL prod2

    The join column is 'col1' (for both sets). Now where there is duplicated in col1; lines Col2 is also double for VALUE 1 and col3 is duplicated for SET 2 and I want the lines in the output as:

    col1 col2 col3
    1 cust prod
    1 cust prod
    2 cust1 prod1
    3 cust2 prod2

    Can you please let me know the best way to achieve this.

    Kind regards
    Miloud

    This operation generates your output given your input samples example, but I don't know why you want four lines instead of the six that would come because of the duplication of the set1.

    SQL> WITH set1 AS (
      2     SELECT 2 col1, 'cust1' col2, NULL col3 FROM dual UNION ALL
      3     SELECT 3, 'cust2', NULL FROM dual UNION ALL
      4     SELECT 1, 'cust', NULL FROM dual UNION ALL
      5     SELECT 1, 'cust', NULL FROM dual),
      6  set2 AS (
      7     SELECT 1 col1, NULL col2, 'prod' col3 FROM dual UNION ALL
      8     SELECT 1, NULL, 'prod'  FROM dual UNION ALL
      9     SELECT 2, NULL, 'prod1' FROM dual UNION ALL
     10     SELECT 3, NULL, 'prod2' FROM dual)
     11  SELECT s1.col1 s1c1, s1.col2 s1c2, s2.col3 s2c3
     12  FROM (SELECT distinct col1, col2, col3 FROM set1) s1
     13     JOIN set2 s2
     14        ON s1.col1 = s2.col1;
    
          S1C1 S1C2  S2C3
    ---------- ----- -----
             1 cust  prod
             1 cust  prod
             2 cust1 prod1
             3 cust2 prod2
    

    John

Maybe you are looking for