Returning multiple date columns in order

Hi,
I was just wondering if there was an easy way of returning a number of date values in order at row level.
An example of the data would be:-
TABLE DATES
P1_DATE P2_DATE P3_DATE P4_DATE
01-JAN-2009 13-FEB-2008 16-JUN-1998 30-SEP-2006
The problem being that in this case I would want to return P3_DATE, P4_DATE, P2_DATE and P1_DATE in this order. However, this would not always be the case as there are no specific rules to state that P3_DATE is before P4_DATE etc.
Any help or advice you could give would be appreciated.
Regards,
ca84

Hi,
For four items, it's not too bad:
SELECT     GREATEST (p1_date, p2_date, p3_date, p4_date)     AS latest_date
,     LEAST ( GREATEST (p1_date, p2_date, p3_date)
           , GREATEST (p1_date, p2_date, p4_date)
           , GREATEST (p1_date, p3_date, p4_date)
           , GREATEST (p2_date, p3_date, p4_date)
           )                              AS second_latest_date
,     GREATEST ( LEAST (p1_date, p2_date, p3_date)
              , LEAST (p1_date, p2_date, p4_date)
              , LEAST (p1_date, p3_date, p4_date)
              , LEAST (p2_date, p3_date, p4_date)
              )                         AS second_earliest_date
,     LEAST (p1_date, p2_date, p3_date, p4_date)      AS earliest_dateFor five items or more, I would un-pivot them into separate rows, assign numbers using ROW_NUMBER, then pivot them back into one row.
This assumes none of the items are NULL. If you can't assume that, use NVL to map NULLs to some impossible date (like TO_DATE (1, 'J')) for the sorting, then use NULLIF to map the impossible dates back to NULL for display.
The solution above does not assume the items as distinct.

Similar Messages

  • Multiple Data Columns in one report column

    How do I list multiple columns returned from a select vertically within one report column. For instance, I have three statuses for a project that I want to list, I'd like to list the three statuses within one status column. I remember seeing this somewhere but cannot find it now. Example:
    Status Column
    Budget: Green
    Schedule: Red
    Issues: Yellow

    additionally you could use HTML expressions. When editing your report, click on the column you want to use for displaying multiple data columns. This will take you to the report columns attributes page, there you can type in something like the following into the HTML expression field, referencing other report columns using #COLUMN_NAME# substitutions:
    #BUDGET#
    #SCHEDULE#
    #ISSUES#
    this is assuming your column aliases are named BUDGET, SCHEDULE and ISSUES. You can then just hide the columns that you don't want to see because the data is already shown using the HTML expression.
    Regards,
    Marc

  • How to load data into Planning/Essbase from multiple data column

    Dear All,
    I have a interface file which contains multiple data column as follows.
    Year,Department,Account,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
    FY10,Department1,Account1,1,2,3,4,5,6,7,8,9,10,11,12
    FY10,Department2,Account1,1,2,3,4,5,6,7,8,9,10,11,12
    FY10,Department3,Account1,1,2,3,4,5,6,7,8,9,10,11,12
    I created a data rule to load these interface file.
    I want to use ODI to upload this interface. I try to specify the rule name in ODI and run the interface.
    But, it came out following errors.
    2010-02-22 11:40:25,609 DEBUG [DwgCmdExecutionThread]: Error occured in sending record chunk...Cannot end dataload. Analytic Server Error(1003014): Unknown Member [FY09,032003,910201,99,0,0,0,0,0,0,0,0,0,0,0,0] in Data Load, [1] Records Completed
    Any idea to fix the column, I sure the member name is correct as I can load data from data load rule correctly.
    Thanks

    Dear John,
    I updated the data load rule delimter to "," and found different error message as follows.
    'A910201.99','HSP_InputValue','HKDepart','No_WT','032003','NO_Lease','FY09','Actual','Final','Local','0','0','0','0','0','0','0','0','0','0','0','0','Cannot end dataload. Analytic Server Error(1003014): Unknown Member [0] in Data Load, [1] Records Completed'
    It seems that the data load rule can recognize the some member except the figures of Jan to Dec..
    thanks for your help

  • Question on Multiple Date columns

    Hello all,
    I have like 7 to 10 fact tables . In each fact table I have one date column..Some facts have 2 or 3 date columns
    for example , I have Activations Fact table in which I have Disconnect_Date and Activation_Date...both should be joined to Date_Dim
    Since , I can't join 2columns from one table to single Date Dim on date_key . I created a alias for Date dim , 1 for Activation_date and the other for Disconnect_date
    Some other fact tables have only one date column . So, i joined all of them to single Date Dim
    Now , In the subject area I will have some facts joined to one Date Dim and Some facts which have multiple date columns joined to their particular alias Date dims...
    like ....
    Subject Area:
    Fact1 (with single date column joined to Date Dim)
    Fact2 ( " )
    Fact3 ( " )
    Fact4 ( " )
    Date Dim (joined to fact1,2,3,4)
    ActivationsFact5 ( fact with 2 date columns)
    Activation_Date ( joined to activationsfact5 on activation_date)
    Disconnect_Date ( joined to activationsfact5 on disconnect_date)
    I have like this...As I know which date dim is joined to what fact I can create reports
    But other users who doesnt have idea on it...may create a report joining activationsfact with Date Dim ,which are not joined
    To avoid this condition , the only way I see is to create aliases of Date Dim for all the facts like Fact1,Date Dim1,Fact2,Date Dim2 like that
    But , I am concerned about creating so many date dims in the rpd. And creating hierarchies for them.
    Does anyone have idea on how to handle this ?? Please help
    Thanks,
    Siri

    Instead of creating aliases of Date Dim for every fact table , do u think its better to train users ?

  • Loading multiple data columns in reserved sign

    Hello,
    Is there a setting to load multiple data columns in reserved sign?
    Thanks,

    Hi Liana,
    To use that formula, you should use CONVERTAMOUNTWDIM  option.
    This options default value is Account dimension but if you want to use different dimension, you should use that dimension name. I guess Building A_65432 is not an account member then you should use below option in the transformation file.
    CONVERTAMOUNTWDIM = dimension name
    This option specifies which dimension to look at for value calculations. You must specify a dimension conversion sheet using the Amount Conversion option. For more information about conversion files, see Data Conversion Maintenance. If there is no formula in the Formula column of the Amount conversion sheet, this parameter has no effect. For example, if the Formula column has the following formula: <value>1.10, all accounts are increased by 10% during the conversion.
    I hope it will help you.
    Regards,
    James Lim

  • SQL Calendar using multiple date columns

    Is there any way to have a Calendar look at more than one date column? I know that it is possible to have the calendar based on a range/interval, but I need to display multiple date columns e.g. Marketing Start Date and Sales Start Date. In the Calendar component it seems possible to only choose one 'Date Column'. Has anyone come across this or know of any workaround?

    Is there any way to have a Calendar look at more than one date column? I know that it is possible to have the calendar based on a range/interval, but I need to display multiple date columns e.g. Marketing Start Date and Sales Start Date. In the Calendar component it seems possible to only choose one 'Date Column'. Has anyone come across this or know of any workaround?

  • How to returns multiple data with function in varray?

    Hi!
    I have 3 rows in my table and i want the return in VARRAY, but
    in my function bottom it works for only one row of my table.
    I don't know how to have the return of values in 3 rows of my table,
    it's possible to have multiple dimension in varray? Or another way for
    having that? Because i read after in java code this result.
    Now my result are :
    RetVal(1)= 504053
    RetVal(2)= 135058
    RetVal(3)= 206734
    I want like :
    RetVal(1)= 504053 Melanie Brown California
    RetVal(2)= 135058 John Smith Boston
    RetVal(3)= 206734 Roy Smith New York
    CREATE TYPE GPDEV.EMPARRAY is VARRAY(100) OF NUMBER
    CREATE FUNCTION MyName RETURN EMPARRAY
    AS
    l_data EmpArray := EmpArray();
    CURSOR c_emp IS SELECT MyTable
    FROM MyRow
    WHERE clientnumber is not null;
    BEGIN
    FOR MyTable IN c_emp LOOP
    l_data.extend;
    l_data(l_data.count) := MyTable.MyRow
    END LOOP;
    RETURN l_data;
    END;
    Thanks in advance for your help!
    Melanie

    Here is one approach...
    CREATE TYPE testType AS OBJECT (test_letter VARCHAR2(2), test_number NUMBER);
    DECLARE
    CURSOR cAAA IS
    select 'a' test_letter, 1 test_number FROM DUAL UNION ALL
    select 'b' test_letter, 2 test_number FROM DUAL UNION ALL
    select 'c' test_letter, 3 test_number FROM DUAL;
    TYPE vArray_testType is VARRAY(100) OF testType;
    testArray vArray_testType:=vArray_testType();
    y number:=0;
    BEGIN
    dbms_output.put('Adding items to varray...');
    FOR rec in cAAA LOOP
    y:=y+1;
    testArray.extend;
    testArray(y):= testType(
    test_letter => rec.test_letter,
    test_number=> rec.test_number);
    END LOOP;
    dbms_output.put_line('Done. ');
    dbms_output.put_line('Print contents of varray...');
    LOOP EXIT WHEN y = 0;
    dbms_output.put_line(testArray(y).test_letter||' '||testArray(y).test_number);
    y := y-1;
    END LOOP;
    dbms_output.put_line('END');
    END;

  • Table partition based multiple date columns

    Hi , I am using Oracle 10G db. One of the source table has 26 million rows. Partition is based on business send date(Quaterly). Now the query that used to load the target table is based on ETL load date. Since the load date is not the partition column,the source query is taking long time to fetch.Can someone please suggest how to include ETL load date in the partition column or if any other way to improve the performance of the source query will be greatly appreciated.Thanks

    Partition is based on business send date(Quaterly).
    Can someone please suggest how to include ETL load date in the partition column
    Technically? Sure - just redefine the table (DBMS_REDEFINITION) and partition it on ETL load data.
    But someone partitioned on 'send date' for a reason didn't they? Don't you think you might want to find out WHY before you even think about changing it?
    The only info you have provided so far is that someone 'thinks' that a single query is 'taking long time to fetch'. That doesn't even mean anything. What is 'long time': 5 seconds, 5 days? How many rows are being fetched out of 26 million: 1, 20 million?
    1. post the table and index DDL
    2. post the query and execution plan
    3. post the command you executed to produce the stats on the table and indexes
    4. post the number of rows for the query predicates
    5. post info about the number of rows in the result set and what you are doing with them

  • First date column in Order

    hI,
    Default of column "First date"
    Is it possible to not fill  "First date" in item overview( ETDAT) with desired delivery date (KETDAT) of the header.?
    if yes can it will be possible for any perticular area?
    regards,
    Anup

    First date is filed which will filled with "Request delivery date " by default though you can change manually.
    its as good as saying that RDD @ Item level.
    Not understood that why you dont want to fill this field? This field is again copied in "Delivery date" field on which basis availability check carried out.
    Regards,
    Reazuddin MD

  • Multiple Date columns  in one fact table

    hi ,
    I have a fact which related to multi date, like bid date, win date, lost date ,etc...,
    I have create dimension like dim_bid_date, dim_win_date,
    but if I wan to create a report , the value sum by the month (2012.01-2012.08), I don't know how to do in one report which related multi date.
    I think I should have a 'common date', how to do, can anyone explain it in detail. thanks.

    2 thinks here, do you want to reports based on bid date,win date, lost date etc?
    if yes you need to create those many date logical tables and you need to have in Subject area (something like 'Agreement Details' subject area if you have OOB rpd)
    Coming to your report requirement 'sum by the month'; I dont think this is complete report requirement, you need to know month type like bid month or win month or lost month or what!!
    if user dont want do report by those mentioned dates then just use just date of type( bid,win etc) with out using day dim;
    you might have some date like created date, create report based on that for sum by the month.
    Hope this helps, if helps pls mark

  • In what order will select * return the data?

    hi guys,
    1) if we just do a select * from emp, will it return the data in the order of the data blocks in the extents. i.e. return all data blocks from extent 1, then from extent 2 and so forth?
    2) if we do a select * from emp, and say half the data blocks are already in the database buffer cache, how does Oracle know that the data blocks from emp are already in the database buffer cache? Does it keep some lookup table?
    thanks

    OracleGuy777 wrote:
    thanks guys,
    I will mark the question as closed, even though I am still a bit unsure as to why if we just start up a database so that the db cache is empty, and do a select * on a small table that is all on one disk, why the Oracle kernel would from a logical point of view choose different order to return the rows.
    but thanks anywayThe order in which rows are returned is a side effect of the execution plan chosen by the Query Optimizer (which is one reason why the ORDER BY clause exists), in plain relational theory both your underlying table and the results are relations (simply an unordered set of tuples) so consequently the optimizer is free to follow whatever method it likes to return the results. In the case of a Rule Based optimizer then there is simply a set of rules that determine the choice of execution plan, in the case of a cost based optimizer then the optimizer attempts to minimize the time taken to return the resultset by choosing an execution plan based on statistical information and algorithms. The existence of the buffer cache is in fact ignored for most practical purposes and certainly for the purposes you imagined.
    Now if your table is just that, a straight forward heap table with no indexes then you will likely get what you expect, that is rows returned in the order that the blocks in which they are held are located on disk; this isn't insert order necessarily by the way especially if ASSM is involved. This is only however because a full tablescan is the only available option for satisfying the query. Most tables however aren't like that, they have indexes, the query involves joins and filters and so on. Once you start allowing the possibility of other access paths then you allow the possibilty that rows or rather blocks will be visited in a different order to the simplistic one described above.
    Niall Litchfield

  • Return multiple values from a Web Service

    Hi,
    I'm learning JAX-WS web services and I'm wondering, how do I return multiple data like, say multiple rows from a table through a web service? I understand that I can use Holders, but those are for JAX-RPC if I'm not mistaken, and I'd like to know the alternative for JAX-WS(if there is any).
    Any help would be much appreciated.

    Debojit Sinha wrote:
    A greeting service where the client types a string(preferably a name), and the service returns "Hello, " followed by that name. I faced the error with returning objects when I tried to return the results of a query with a set of serialized JavaBeans passed into an arraylist. I don't have the complete error log with me now, but the error was generated when deploying with JDeveloper 11g, and it was something about JAXB content model error. Also, There was an error regarding javax.naming.Name saying that JAXB couldn't handle interfaces.yes, you can't return any interfaces. so, instead of returning a List, you have to return an ArrayList. if you use xjc to generate types from a schema, then it will normally generate a "wrapper" class around any collections (which will in turn hold a List).

  • Multiple Date Fields (Fact Table) - Linking with Time Dimension

    I have a fact table that has multiple date columns.
    I can make a time dimension, but it has to be joined to a particular date column. This becomes difficult because of the limit in having multiple date fields reference one time dimension. I can see possibly
    creating a date table which contains all dates, link to fact as well as time dimension table. I am trying to better visualize the table layout on this one. Or are there possibily better ways of looking at this senerio
    Any idea's

    Figured this one out; going to use one time dimension - what looking too much into the details in regard to this scenerio

  • Problems with DATE columns in 9.2.0.4 using JDBC

    In Oracle 9.2.0.4.0, it seems Oracle has yet again altered the way it JDBC drivers return Oracle DATE columns. These columns now only refer to date information; the Oracle type TIMESTAMP now is used to contain date and time information. Since my application does not support java.sql.Date, it is reporting that some columns cannot be populated, because the type is unsupported.
    Is there anyway that I can get my Oracle DATE columns to return java.sql.Timestamp objects ?
    This seems like a bug on Oracle's part--we have a column that stores date and time data (an Oracle DATE column), and the Oracle JDBC driver tells us that the column only stores a date (it reports it as java.sql.Date).
    I am using oracle.jdbc.OracleDriver.
    Thanks,
    Amit

    did you migrate the database or just install the 9.2.0.8 software?
    After database upgrade, your database and the software should have the same version:
    <i><b>select version from v$instance</b></i>; (software version)
    <i><b>select comp_id,version,status from dba_registry;[/</b>i] (database version)
    How are the environment settings of <sid>adm?
    Run please R3trans -d or R3trans -x and post the trans.log.  Could you please also check the developer traces, if there are any other errors?
    Best regards
    Baran

  • SELECT in SELECT returning multiple columns ?

    10.2.0.3 version.
    I am trying to tune this query
    SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
    (SELECT A1.DESCR FROM PS_ACAD_PROG_TBL A1
    WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
    (SELECT A2.DESCRSHORT FROM PS_ACAD_PROG_TBL A2
    WHERE A2.INSTITUTION = 'AUAO1' AND A2.ACAD_PROG = A.ACAD_PROG AND A2.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A2.INSTITUTION AND ACAD_PROG = A2.ACAD_PROG),
    as you can see it reading the table PS_ACAD_PROG_TBL two time to get two cloumns DESCR (alias A1) and DESCRSHORT (alias A2) exactly with the same where condition.
    I am trying to replace it with just one select returning multiple columns like this
    SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
    (SELECT A1.DESCR, A1.DESCRSHORT FROM PS_ACAD_PROG_TBL A1
    WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
    but I am getting ORA-00913: too many values.
    Please help on how to get around this. Thanks in advance.

    William,
    On similar lines I am struggling with the below query based on your suggestions.
    SQL*Plus: Release 9.2.0.1.0 - Production on Wed Aug 5 14:17:21 2009
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> WITH arch_dup AS
      2       (SELECT   a.file_id,
      3                 a.sale_start,
      4                 a.activity_start,
      5                 a.activity_end,
      6                 a.item_code_cust,
      7                 a.division,
      8                 (SELECT MAX (DISTINCT (NVL (b.advertised, 'No')))
      9                    FROM ah_cust_gis_arch_stg b
    10                   WHERE b.file_id = a.file_id
    11                     AND NVL (b.sale_start, 'NULL') = NVL (a.sale_start, 'NULL')
    12                     AND NVL (b.activity_start, 'NULL') = NVL (a.activity_start, 'NULL')
    13                     AND NVL (b.activity_end, 'NULL') = NVL (a.activity_end, 'NULL')
    14                     AND b.item_code_cust = a.item_code_cust
    15                     AND b.division = a.division) advertised,
    16                 COUNT (*)
    17            FROM ah_cust_gis_arch_stg a
    18           WHERE a.file_id = 209
    19             AND a.status_id = 21
    20        GROUP BY a.file_id, a.sale_start, a.activity_start, a.activity_end, a.item_code_cust, a.d
    ivision
    21          HAVING COUNT (*) > 1)
    22  SELECT dup.*,
    23         (SELECT activity_id
    24            FROM (SELECT activity_id,
    25                         ROW_NUMBER () OVER (ORDER BY (activity_retail / activity_mult)) rnk
    26                    FROM ah_cust_gis_arch_stg
    27                   WHERE status_id = 21
    28                     AND NVL (sale_start, 'NULL') = NVL (dup.sale_start, 'NULL')
    29                     AND NVL (activity_start, 'NULL') = NVL (dup.activity_start, 'NULL')
    30                     AND NVL (activity_end, 'NULL') = NVL (dup.activity_end, 'NULL')
    31                     AND item_code_cust = dup.item_code_cust
    32                     AND division = dup.division
    33                     AND file_id = 209
    34                     AND UPPER (NVL (advertised, 'N')) = dup.advertised)
    35           WHERE rnk = 1) activity_id
    36    FROM arch_dup dup;
                       AND UPPER (NVL (advertised, 'N')) = dup.advertised)
    ERROR at line 34:
    ORA-00904: "DUP"."ADVERTISED": invalid identifierCan you throw some light on what to do to make the outer query columns available to inner query?
    Thanks,
    Raj.

Maybe you are looking for

  • How to eject a disk from an extern drive?

    how to eject a disk from an extern drive? I burned a few disc and it worked then I put another blank disc and now I cannot make it eject or burn...Please help

  • Stop printing multiple pages on one sheet

    When printing from Acrobat or Reader, the print preview and settings show that I am printing a single page on one sheet of paper. However, it actually prints two pages side-by-side on one sheet of paper. How would I stop this? This is the only progra

  • Extend TextInput

    Hi -- I am just beginning to migrate from ActionScript 2 to Actionscript 3. I would like to create a simple custom control with the TextInput as the base component and just a few custom properties of my own to help me understand how AS 3 works. I hav

  • Nano 6 Griffen adapter vs apple

    I wanted a black cord for my ipod nano 6. Purchased a Griffin adapter. Some issues with my USB and car functions for ipod... Will the cord make any difference on ipod functions or are all cords the same?

  • Find My Friends - Apple ID issue... Help

    Hi, I've been using Find My Friends on my @me.com account. But since I've changed all my devices from @me.com accounts to @icloud.com accounts it doesn't work. It says at the bottom of the Find My Friends app, Signed in as ******@icloud.com but the "