Sql to fetch values for missing records.

Hi All,
I'm working on oracle 10gR2.I'm having trouble writing a query for the below and I know you genious guys can help me.
I have the below table data.
The data is read as....for Name R-VA013SC between from_m 0 and to_m 0.5 the average daily value is 30 and volume is 34 for the year 1929.
similarly next record for Name R-VA013SC between from_m 0 and to_m 0.5 the average daily value is 40 and volume is 43 for the year 2001.
"NAME" | "FROM_M"|"TO_M"|"DATA_DATE"|"ADT""VOLUME"
"R-VA013SC"     | 0     |0.05     | *01-JAN-29......|*     30 |     34     
"R-VA013SC"     | 0     |0.05     | *12-SEP-01..*....| 40 |     43     
"R-VA013SC"     | 0     |0.05     | *14-JAN-08.......|*     20 |     15     
if you notice above, there are data missing for years from 1930 to 2000, the daily average and volume is assumed to be the previously available year, for example for the year 2000, we need to have a record with the data for 1929 with the current date like
"R-VA013SC"     | 0     |0.05     | *01-JAN-00.....|*     30 |     34     
for the year 2005 , the data has to copied from 2001 like .
"R-VA013SC"     | 0     |0.05     | *12-SEP-05*......| 40 |     43
for the year 2009, the value has to be fetched from the previously available year ie 2008 like
"R-VA013SC"     | 0     |0.05     | *14-JAN-09*.......|     20 |     15.
I aslo need to write a query to find the average values between 2 years,
like if someone asks for the average volume adt ADT between 2000 and 2005, I need to find the average of the same
like ... add the averages for 2000-2005/no of years requested(5).
Appreciate all your help!
Thanks in advance
H

Hi,
user32322435 wrote:
Thanks again..
Here is the table data
ID     NAME     FROM_M     TO_M     ADT     VOLUME     DATA_DATE
2055801     SC-723N      0     0.05     30     34     01/01/1929
2055801     SC-723N      0     0.05     40     43     09/12/2001
2055801     SC-723N      0     0.05     20     15     01/14/2008I'm considering the following
start date ='1999-07-01'
end date ='2003-07-01'
end_date-start_date = 1461
So,
days considered in 1999 is 184 *adt for 1999 is 30 = 5520
days considered in 2000 is *366(leap year)* *adt for 2000 is 30 = 10980
days considered in 2001 is 365 *adt for 2001 is 40 = 14600
days considered in 2002 is 365 *adt for 2001is 40 = 14600
days considered in 2003 is 184 *adt for 2003 is 40= 7360January 1 through July 1, 2010 is only 182 days, isn't it? That would make the total for 2003 = 7280 (net loss of 80).
>
5520+10980+14600+14600+7360 = 53060/no of days taken into account (1461)July 1, 1999 through July 1, 2003 inclusive is 1462 days, right? 4 * 365 = 1460, plus one February 29th, plus an extra July 1st.
Expected ADT 53060/1461 =*36.31* With the corrections mentioned above, that's 52980 / 1462 = 36.23 (rounded).
......very sorry about the 38.01 . I missed something earlier.
(select to_date('2003-07-01','YYYY-MM-DD') - to_date('1999-07-01','YYYY-MM-DD') from dual;) = 1461That's the number of days between the two. You have to add 1 if both endpoints are to be included.
1999-07-01 through 1999-07-01 is 1 day, but the difference is 0.
select to_date('1999-12-31','YYYY-MM-DD') - to_date('1999-07-01','YYYY-MM-DD') +1 from dual; = 184Now I understand!
Until this message I had no idea that you wanted data_date rounded down to the beginning of the year, no matter how late in the year it actually is.
In that case, replace data_date in the sub-query with TRUNC (data_date, 'YEAR'), and the previous query will do what you requested:
WITH   params                      AS
     SELECT     DATE '1999-07-01'     AS begin_date
     ,     DATE '2003-07-01' + 1     AS end_date
     FROM dual
,     got_next_data_date     AS
     SELECT  id
--     ,     data_date          -- REPLACED WITH FOLLOWING LINE
     ,     TRUNC (data_date, 'YEAR')     AS data_date
     ,     adt
     ,     LEAD (
              -- data_date     -- REPLACED WITH FOLLOWING LINE
                 TRUNC (data_date, 'YEAR')
               , 1
               , DATE '9999-12-31'
               ) OVER ( PARTITION BY  id
                              ORDER BY      data_date
                       ) AS next_data_date
     FROM    table_test
SELECT       n.id
,       SUM ( n.adt
           * ( LEAST ( next_data_date
               , p.end_date
          - GREATEST ( n.data_date
                    , p.begin_date
           ) / (p.end_date - p.begin_date)      AS avg_adt
FROM       got_next_data_date  n
JOIN       params           p       ON     n.data_date     <= p.end_date
                        AND     p.begin_date     <= n.next_data_date
GROUP BY  id
;Of course, you don't need the lines marked "REPLACED WITH FOLLOWING LINE". I left them there in case you were wondering how the query had changed.
I also used id, instead of name, for GROUPing and PARTIONing, since that seems to reflect your posting. If one is functionally dependent on the other, then it doesn't matter which one you use.
... our expectation for select * from new view should be some thing like ...for those missing year the dates can be defaulted to 01_JAN. the available years are spaced just to differentiate
ID     NAME     FROM_M     TO_M     ADT     VOLUME     DATA_DATE
2055801     SC-723N      0     0.05     40     43     01/01/1999
2055801     SC-723N      0     0.05     40     43     01/01/2000
2055801     SC-723N      0     0.05     40     43     09/12/2001
2055801     SC-723N      0     0.05     20     15     01/01/2002
2055801     SC-723N      0     0.05     20     15     01/01/2003
2055801     SC-723N      0     0.05     20     15     01/01/2004
2055801     SC-723N      0     0.05     20     15     01/01/2005
2055801     SC-723N      0     0.05     20     15     01/01/2004
2055801     SC-723N      0     0.05     20     15     01/01/2005
2055801     SC-723N      0     0.05     20     15     01/01/2006
2055801     SC-723N      0     0.05     20     15     01/01/2007
2055801     SC-723N      0     0.05     20     15     01/14/2008
2055801     SC-723N      0     0.05     20     15     01/01/2009
This does what you requested.
It includes all years from the earliest data_date through either (a) the last data_date, or (b) the current year, whichever is later.
CREATE OR REPLACE VIEW     yearly_view
AS
WITH     got_years_in_effect     AS
     SELECT     id, name, from_m, to_m, adt, volume, data_date
     ,     MONTHS_BETWEEN ( LEAD ( TRUNC (data_date, 'YEAR')
                                 , 1
                          , ADD_MONTHS ( TRUNC (SYSDATE, 'YEAR')
                                       , 12
                          ) OVER ( PARTITION BY  id
                                      ORDER BY          data_date
                    , TRUNC (data_date, 'YEAR')
                    ) / 12          AS years_in_effect
     FROM     table_test
,     cntr     AS
     SELECT     LEVEL     AS n
     FROM     (
               SELECT  MAX (years_in_effect)     AS max_years
               FROM     got_years_in_effect
     CONNECT BY     LEVEL <= max_years
SELECT     y.id, y.name, y.from_m, y.to_m, y.adt, y.volume
,     CASE
          WHEN  c.n = 1
          THEN  y.data_date
          ELSE  ADD_MONTHS ( TRUNC (y.data_date, 'YEAR')
                           , 12 * (c.n - 1)
     END     AS data_date
FROM     got_years_in_effect y
JOIN     cntr              c     ON     c.n     <= y.years_in_effect
;

Similar Messages

  • How to have a unique value for each record??

    could any 1 help me out in this...
    I want to have a column name 'Order No' which should be unique.
    How to generate a unique value for each record.??

    could any 1 help me out in this...
    I want to have a column name 'Order No' which should be unique.
    How to generate a unique value for each record.?? If you are using SQL PLUS to create the table try something like
    this:
    CREATE TABLE ORDER_TEST (
    ORD_NO NUMBER (8) NOT NULL PRIMARY KEY,
    ORDERDATE DATE,
    CUSTID NUMBER (8) NOT NULL,
    SHIPDATE DATE,
    TOTAL NUMBER (8,2) CONSTRAINT TOTAL_ZERO CHECK
    (TOTAL >= 0),
    CONSTRAINT ORD_FOREIGN_KEY FOREIGN KEY (CUSTID) REFERENCES
    CUSTOMER (CUSTID),
    CONSTRAINT ORD_UNIQUE UNIQUE (ORD_NO)
    -- or a simpler table example
    DROP TABLE ORDER_TEST;
    CREATE TABLE ORDER_TEST (
    ORD_NO NUMBER (8),
    ORDERDATE DATE,
    CUSTID NUMBER (8) NOT NULL,
    SHIPDATE DATE,
    TOTAL NUMBER (8,2) CONSTRAINT TOTAL_ZERO CHECK
    (TOTAL >= 0),
    CONSTRAINT ORD_UNIQUE UNIQUE (ORD_NO)
    note: ORD_NO can also be a primary key
    If you are doing the INSERT during runtime from a form first
    create a sequence in SQL PLUS to handle the ORD_NO value:
    Create SEQUENCE ORDERNO_UNIQUEVAL_sqnc
    START WITH 000001
    NOMAXVALUE
    NOCACHE;
    and reference it as the ORD_NO parameter in your INSERT
    statement:
    ORDERNO_UNIQUEVAL_sqnc.NEXTVAL
    note: to maintain data integrity you must use the sequence
    everytime you insert a new order to table. To start a new
    sequence drop the sequence and re-create it with whatever "START
    WITH" value you want.
    Hope this helps
    Kevin

  • How to show multiple values for Unique records in Report

    Here's my question/problem:
    I've joined two tables, one table (TBL1) contains an object id (OBJ_ID) that repeats and the other table (TBL2) contains a date (DT), object type id (OBJ_TYP_ID), and object type description (OBJ_TYP_DES). The tables are joined by an inventory id (INV_ID).
    The OBJ_ID repeats and has a Date value for each record. I want to report an unique OBJ_ID and show each Date for a particular OBJ_ID in multiple Columns.
    An example of the current resultset looks like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYP_DES DATE
    1 1 TYPE1 4/1/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009
    1 2 TYPE2 5/3/2009
    3 1 TYPE1 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    1 1 TYPE1 4/3/2007
    1 1 TYPE1 3/30/2005
    I want to express the resultset like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
    1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
    1 2 TYPE2 5/3/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?

    Hi,
    cclemmons wrote:
    I want to express the resultset like this:
    OBJ_ID OBJ_TYP_ID OBJ_TYPE_DES DATE1 DATE2 DATE3
    1 1 TYPE1 4/1/2009 4/3/2007 3/30/2005
    1 2 TYPE2 5/3/2009
    2 1 TYPE1 4/1/2009
    3 1 TYPE1 4/10/2009 3/30/2005
    4 1 TYPE1 4/1/2009
    5 1 TYPE1 4/1/2009
    5 2 TYPE2 5/1/2009
    What technique is best to use to do this? I know I could create another table and populate the rows/columns by reading data from this query, but is there a better way?Absolutely! You seem to have an instictive feeling that creating a separate table just for a query is inefficient. You instinct is 100% correct. Maybe in Oracle 7 there was a reason to do that, but today you can query results of other queries as if they were tables, so temporary tables like you describe are very rarely necessary, let alone convenient.
    What you want to do is pivot the date columns. Here's one way
    WITH     original_query     AS
         SELECT  obj_id
         ,     obj_typ_id
         ,     obj_typ_des
         ,     dt          -- date is not a good column name
         FROM     ...          -- the rest of your original query goes here
    ,     got_rnum     AS
         SELECT     oq.*
         ,     ROW_NUMBER () OVER ( PARTITION BY  obj_id
                                   ,                    obj_typ_id
                             ,             obj_typ_des
                             ORDER BY        dt     DESC
                           )         AS rnum
         FROM    original_query        oq
    SELECT       obj_id
    ,       obj_typ_id
    ,       obj_typ_des
    ,       MAX (CASE WHEN rnum = 1 THEN dt END)     AS dt1
    ,       MAX (CASE WHEN rnum = 2 THEN dt END)     AS dt2
    ,       MAX (CASE WHEN rnum = 3 THEN dt END)     AS dt3
    ,       MAX (CASE WHEN rnum = 4 THEN dt END)     AS dt4
    ,       MAX (CASE WHEN rnum = 5 THEN dt END)     AS dt5
    FROM       got_rnum
    GROUP BY  obj_id
    ,       obj_typ_id
    ,       obj_typ_des
    ;As you can see, this adds two layers of queries on top of your original query. One of those layers is probably not needed; depending on what you're doing in your original main query, you can probably compute rnum there, and omit the got_rnum sub-query.
    Also, depending on the relationship of obj_id, obj_typ_id and obj_typ_des, some of what I posted above may not be needed but including it won't really hurt.
    If you want to know more about this technique, search for "pivot" or "rows to columns". A <tt>SELECT ... PIVOT ...</tt> keyword was introduced in Oracle 11, but most of what you'll find when you search for "pivot" doesn't assume you have Oracle 11 (nor does the query above require Oracle 11).
    This assumes you know an upper limit (5 in the example above) of dts that can appear in any line of output.
    See [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=3527823&#3527823] for a discussion of some alternatives.

  • Inserting values for all records except 1 or 2 column ,without specify column names.,?

    Hi,
    for example, in student table i am having 1000 columns,  column names like(id ,name,class, dept,etc,.).
    i want to insert 998 fields to department table from student tables except(id,class).
    i don't want to mention all column names in the insert command,
    is there any possibilities to filter the column names in insert command like (EXCEPT, NOT IN).
    Thanks in advance..

    duplicate of
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b31fa034-5b8f-42e4-b4e1-592a632ca6a5/inserting-values-for-all-records-except-1-or-2-column-without-specify-column-names?forum=sqlce
    please dont cross post
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • Puzzle why query returned wrong value for last record in update.

    Hi all,
    10.2.0.4, Windows 32 bit.
    Apply 15% dis.count to related 5 items ( total amount 522 ) sorted by lowest amount first (amount = 1).
    Last record ( amount = 200 ) will be the total dis.count amount ( 78.3 ) less applied accumulated dis.count amount ( 48.50 ).
    Query runs fine without update clause but wrong result for last record with update.
    CREATE TABLE "T1"
        "ID"       NUMBER NOT NULL ENABLE,
        "ITEM_ID"  VARCHAR2(20 BYTE) NOT NULL ENABLE,
        "AMOUNT"   NUMBER(10,2) NOT NULL ENABLE,
        "dizcount" NUMBER(10,2)
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '101', 1, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '102', 1, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '201', 200, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '215', 155, NULL ) ;
    INSERT INTO T1 ( ID, ITEM_ID, AMOUNT, dizcount )  VALUES ( 65, '111', 165, NULL ) ;
    UPDATE t1 a
    SET a.dizcount =
      (SELECT
        CASE
          WHEN rec_count = row_count
          THEN (78.3 - NVL(lag(temp_total,1) over ( order by rec_count) ,0))-- 78.3 is total dizcount amount from 522 * .15
          ELSE disc_amt
        END amt
      FROM
        (SELECT id,
          item_id,
          disc_amt,
          rec_count,
          row_count,
          CASE
            WHEN rec_count != row_count -- accumulate dizcount amount except for last record
            THEN SUM(disc_amt) over (order by rec_count)
            ELSE 0
          END temp_total
        FROM
          (SELECT ID ,
            item_id,
            amount amt,
            ROUND(amount * .15,1) disc_amt, -- dizcount is 15%
            row_number () over (order by amount) rec_count,
            COUNT ( *) over () row_count
          FROM t1
          WHERE ID = 65
        GROUP BY id,
          item_id,
          disc_amt,
          rec_count,
          row_count
        )b
      WHERE a.item_id = b.item_id
      );Regards
    Zack
    Edited by: Zack.L on Jul 26, 2010 1:26 AM

    Zack.L wrote:
    Query runs fine without update clause but wrong result for last record with update.Not sure why but looks like another case in favour of MERGE.
    MERGE INTO T1
    using (SELECT id, item_id,
        CASE
          WHEN rec_count = row_count
          THEN (78.3 - NVL(lag(temp_total,1) over ( order by rec_count) ,0))-- 78.3 is total dizcount amount from 522 * .15
          ELSE disc_amt
        END amt
      FROM
        (SELECT id,
          item_id,
          disc_amt,
          rec_count,
          row_count,
          CASE
            WHEN rec_count != row_count -- accumulate dizcount amount except for last record
            THEN SUM(disc_amt) over (order by rec_count)
            ELSE 0
          END temp_total
        FROM
          (SELECT ID ,
            item_id,
            amount amt,
            ROUND(amount * .15,1) disc_amt, -- dizcount is 15%
            row_number () over (order by amount) rec_count,
            COUNT ( *) over () row_count
          FROM t1
          WHERE ID = 65
        GROUP BY id,
          item_id,
          disc_amt,
          rec_count,
          row_count
        ))b
    on (t1.id = b.id and t1.item_id = b.item_id)
    when matched then update set dizcount = b.amt ;This worked for me. I tested on 11.2 but should work on 10.2.0.4
    SQL> select * from t1 order by amount ;
            ID ITEM_ID                  AMOUNT   DIZCOUNT
            65 101                           1         .2
            65 102                           1         .2
            65 215                         155       23.3
            65 111                         165       24.8
            65 201                         200       29.8p.s. BTW, not sure if you want the column names in different cases, but your script, as it is, gave me an error (on 11.2)

  • Insert into .. sql return incorrect value for 2 columns,sometime no value

    Hello,
    Oracle 10.2.0.3 , sol 10. (recently upgraded from oracle9i & sol8)
    sql query is used to populate a table. sometimes it is populating same values for all the records in 2 columns. Sometimes not populating or partially populating 1 other column. other times its running fine.
    SQL is not changed at all. When run again , it populates correctly.
    any help is highly appreciatied.
    --pooja                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    no ORA errors while execution. Its completing successfully.
    and its an intermittent issue. when the SQL is run manually its gives perfect results. Rerunnign the entire process is also fine. Conclusivly, data & SQL has no problem.
    its an insert into table <SQL>
    SQL contains left outer join.
    example:
    Expected output:
    1 john texas
    2 smith MA
    3 rob michigan
    Actual Output
    1 john texas
    2 smith texas
    3 rob texas

  • Custom Report Not fetching values for parameter of report (Valueset not pop

    Hi,
    I am running custom report on Oracle application R12. This report parameters used standard value set for fetching purchase order number. The value set is not populating any values for the custom report. but for the standard report where this valuse set populating proper result.
    It's bit Supprising ...the same valuset populating values for standard reports but not for custom report developed by me.
    Value set query using table valueset and getting values from po_headers (View)
    Thanks

    Hi All,
    Luckily I have been able to rectify the problem !
    I tried retrieving the output using LISTCUBE to show the SID of the InfoObject  also for which I was unable to get the data. After the report successfully gave the output for those I/O, I checked again I could see the data in the I/O maintain master data !
    It worked like magic to me !
    But I could guess that since it is a virtual I/O therefore it is not able to retrieve the data from the table directly and is able to do that only after the SID of this I/O is retrieved.
    (If a characteristic does not have any master data, the values from the SID table are displayed for the "Values in Master Data Table" mode.)
    Closing the thread !
    Regards
    Shalabh

  • Insert three values for each record

    I have a very complex Data Flow, with several joins, splits, etc.... once all of this logic is completed, I need to insert the values 2013, 2014, and 2015 for a Derived Column (called Year).  Each record that comes through this data flow needs to have
    a duplicated entry three times, and insert these values for the year.
    Here's a simple example source:
    Key Name
    1 Brandon
    2 Thomas
    So the target should end up being:
    Key Name
    Year
    1 Brandon
    2013
    2 Brandon
    2014
    3 Brandon
    2015
    4 Thomas
    2013
    5 Thomas
    2014
    6 Thomas
    2015
    Can anyone help?
    There are only 10 types of people in the world... those who know binary, and those who don't.

    Hi,
    Try this,
    1. Load the data into your destination with 2013 as a derived column.
    2. Have an another Dataflow task to load one more time. (Select the distinct record from dest table - have an id key and take distinct based on that or please check for your data nature). After selecting the distinct records, have 2014 as derived column
    in that DFT.
    3. Again have another DFT to load for 2015.
    This is a static method since you have only 3 years to insert. If you have more years like this, do a loop to achieve this logic.
    --------------------Mark as Answered or Vote as helpful if this solves your problem.------------------

  • Need PL/SQL Command for to check all rows value for child record and update

    Hi All,
    i want to update one field following by
    one to many relationship for example
    in child applet status field is value is "Closed" for all child record then parent value also should update to closed
    Note: if one child record field status is "Open" don't do the update operation

    You can do it in single UPDATE operation.
    Here is sample & Result:
    create table PA (id varchar2(3), name varchar2(12), STATUS varchar2(12));
    insert into pa values('001','Cary','Open');
    insert into pa values('002','TOM','Open');
    create table boy (par_id varchar2(3), id varchar2(4), name varchar2(12), status varchar2(12));
    insert into boy values('001','ABC1','Cary','Open');
    insert into boy values('001','ABC2','Mac','Closed');
    insert into boy values('001','ABC3','Ray','Closed');
    insert into boy values('001','ABC4','NALLY','Open');
    insert into boy values('002','ABC5','ME','Closed');
    insert into boy values('002','ABC6','SHE','Closed');
    UPDATE PA
    SET STATUS='Closed'
    WHERE NOT EXISTS
      (SELECT 1
      FROM BOY
      WHERE BOY.PAR_ID=PA.id
      GROUP BY BOY.PAR_ID,
        BOY.STATUS
      HAVING SUM(DECODE(BOY.STATUS,'Open',1,'Closed',0,0))>0
    select * from pa;
    001     Cary     Open
    002     TOM     Closed

  • Predict / fill in values for missing values

    Hi,
    We have some readings taken for each patient for every month for the complete year. If there are any points missing for a patient for certain month, is there any function or something that Oracle provides to fill in for this point. We know that SAS has such function. Could you please let me know if Oracle has such facility? Thanks,
    Lakshmi

    Hi Lakshmi,
    Oracle offers a number of linear regression methods. (I think as of version 9i)
    Maybe you should have a look at them :
    REGR_SLOPE     returns the slope of the line. The return value is a number and can be null. After the elimination of null (expr1, expr2) pairs, it makes the following computation:
    COVAR_POP(expr1, expr2) / VAR_POP(expr2)
    REGR_INTERCEPT     returns the y-intercept of the regression line. The return value is a number and can be null. After the elimination of null (expr1, expr2) pairs, it makes the following computation:
    AVG(expr1) - REGR_SLOPE(expr1, expr2) * AVG(expr2)
    REGR_COUNT     returns an integer that is the number of non-null number pairs used to fit the regression line.
    REGR_R2     returns the coefficient of determination (also called "R-squared" or "goodness of fit") for the regression. The return value is a number and can be null.
    REGR_AVGX     evaluates the average of the independent variable (expr2) of the regression line. It makes the following computation after the elimination of null (expr1, expr2) pairs:
    AVG(expr2)
    REGR_AVGY     evaluates the average of the dependent variable (expr1) of the regression line. It makes the following computation after the elimination of null (expr1, expr2) pairs:
    AVG(expr1)
    REGR_SXX     makes the following computation after the elimination of null (expr1, expr2) pairs:
    REGR_COUNT(expr1, expr2) * VAR_POP(expr2)
    REGR_SYY     makes the following computation after the elimination of null (expr1, expr2) pairs:
    REGR_COUNT(expr1, expr2) * VAR_POP(expr1)
    REGR_SXY     makes the following computation after the elimination of null (expr1, expr2) pairs:
    REGR_COUNT(expr1, expr2) * COVAR_POP(expr1, expr2)
    REGR_SXY, REGR_SXX, REGR_SYY are auxiliary functions that are used to compute various diagnostic statistics.
    Best Regards,
    Kris

  • PAAPINVW -- how to fetch values for invoice line level details

    My requirement is such that we define one of our account segments at invoice line dff's while creating the invoice against a project. So the ccid would need to driven from this invoice line dff, to be complete and valid.
    Project Supplier Invoice Account Generator (PAAPINVW) has already defined attributes for Invoice Header DFF's and Invoice Distribution level DFF's; but Invoice line level DFF's have not been defined.
    Also there are no attributes that would help me query the invoice line to fetch these details.
    Working on this workflow in R12. Has anyone tried to fetch any sort of details from invoice lines, using any existing attributes in PAAPINVW; or has anyone done something in accordance to this??
    Looking for suggestions.. have anyone faced a similar situation before??

    Hi user;
    Pelase check below note cause and solution part please,which at least can gives u some ideas
    Projects Supplier Invoice Account Generation Error: APP-SQLAP-97734: The System Cannot Generate Distributions [ID 823787.1]Regard
    Regard
    Helios

  • SQL Loader Null Value for Date

    Dear buddies,
    This is how my date column is in my control file.
    dtEdu timestamp(6) with local time zone "YYYY-MM-DD HH24:MI:SS"  "nvl (to_date (:dtEdu, 'YYYY-MM-DD HH24:MI:SS'), to_date ('1982-03-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'))",  The problem is some of the columns in dtEdu has NULL values and I couldn't load them.
    So, trying to replace it with something else.
    Could someone help me?
    Thanks a lot.
    Nith

    >
    The problem is some of the columns in dtEdu has NULL values and I couldn't load them.
    >
    I don't know how your so called "NULL" values look like, but if the null data is actually made up of blanks, try adding LTRIM() around :dtEdu.

  • Just need the record from the right (many) table with the max value for the Record on the left (one) side table

    SELECT
      ADHOC.ATS_ESH.Entry_Num
      ,ADHOC.ATS_ESH.Importer
      ,ADHOC.ATS_ESH.Version AS [ATS_ESH Version]
      ,ADHOC.ATS_ESL.Version AS [ATS_ESL Version]
    FROM
      ADHOC.ATS_ESH
      INNER JOIN ADHOC.ATS_ESL
        ON ADHOC.ATS_ESH.Customs_Entry_Num = ADHOC.ATS_ESL.Customs_Entry_Num
    I just need to see the MAXIMUM version number in the ESL table for each Entry_Num in the ESH table. ESH is the one side, ESL is the MANY side.

    Do you understand what this query is doing? Did you check the blogs I pointed you to?
    The query I provided gets the latest ESL version for each custom number. So, if max ESL version is higher than ESH version, it's just a coincidence. If you only want to see rows where versions do not match, just add an extra where condition, e.g.
    SELECT * FROM cte WHERE Rn = 1
    AND  [ATS_ESH
    Version] <>  [ATS_ESL
    Version]
    BTW, what is the type of these version
    columns and what kind of data in them? If they are character columns, sorting them in DESC order will not necessary return the latest version. Can you show some samples of the data in these two columns?
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Insert missing records dynamically in SQL Server 2008 R2

    Hi, I am working on a requirement where I will have to work on some % calculations for 2 different states where we do business. The task that I am trying to accomplish is technically we need to have any Product sales in both the states if not for instance
    in the following example ProductC does not have sales in OR so I need to insert a record for ProductC - OR with 0. This is an intermediary resultset of all the calculations that I am working with.
    Example Dataset:
    CREATE TABLE [dbo].[Product](
    [Product] [varchar](18) NOT NULL,
    [State] [varchar](5) NOT NULL,
    [Area1] [int] NOT NULL,
    [Area2] [int] NOT NULL,
    [Area3] [int] NOT NULL,
    [Area4] [int] NOT NULL,
    [Area5] [int] NOT NULL,
    [Area6] [int] NOT NULL,
    [Area7] [int] NOT NULL,
    [Area8] [int] NOT NULL,
    [Area9] [int] NOT NULL,
    [Area10] [int] NOT NULL,
    [Total] [int] NULL
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','OR',0,0,2,0,2,0,0,0,0,0,4)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','WA',0,0,1,0,0,0,0,0,0,0,1)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','Total',0,0,3,0,2,0,0,0,0,0,5)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','OR',0,0,5,0,0,0,0,0,0,0,5)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','WA',0,0,2,0,0,1,0,0,0,0,3)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','Total',0,0,7,0,0,1,0,0,0,0,8)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductC','WA',0,0,0,0,0,0,0,0,0,1,1)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductC','Total',0,0,0,0,0,0,0,0,0,1,1)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','OR',5,2,451,154,43,1,0,0,0,0,656)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','WA',0,20,102,182,58,36,0,1,0,0,399)
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','Total',5,22,553,336,101,37,0,1,0,0,1055)
    How to accomplish this in SQL Server 2008 R2.
    Insert missing record:
    INSERT INTO [Product] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductC','OR',0,0,0,0,0,0,0,0,0,0,0)
    Thanks in advance......
    Ione

    CREATE TABLE [dbo].[Products](
    [Product] [varchar](18) NOT NULL,
    [State] [varchar](5) NOT NULL,
    [Area1] [int] NOT NULL,
    [Area2] [int] NOT NULL,
    [Area3] [int] NOT NULL,
    [Area4] [int] NOT NULL,
    [Area5] [int] NOT NULL,
    [Area6] [int] NOT NULL,
    [Area7] [int] NOT NULL,
    [Area8] [int] NOT NULL,
    [Area9] [int] NOT NULL,
    [Area10] [int] NOT NULL,
    [Total] [int] NULL
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','OR',0,0,2,0,2,0,0,0,0,0,4)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','WA',0,0,1,0,0,0,0,0,0,0,1)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductA','Total',0,0,3,0,2,0,0,0,0,0,5)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','OR',0,0,5,0,0,0,0,0,0,0,5)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','WA',0,0,2,0,0,1,0,0,0,0,3)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductB','Total',0,0,7,0,0,1,0,0,0,0,8)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductC','WA',0,0,0,0,0,0,0,0,0,1,1)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductC','Total',0,0,0,0,0,0,0,0,0,1,1)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','OR',5,2,451,154,43,1,0,0,0,0,656)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','WA',0,20,102,182,58,36,0,1,0,0,399)
    INSERT INTO [Products] ([Product],[State],[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])VALUES('ProductD','Total',5,22,553,336,101,37,0,1,0,0,1055)
    ;WIth mycte as (
    Select Product,State From (Select distinct Product from Products) p, (
    Select distinct State from Products) s
    Insert into [Products](Product,State,[Area1],[Area2],[Area3],[Area4],[Area5],[Area6],[Area7],[Area8],[Area9],[Area10],[Total])
    Select m.Product,m.State
    ,0,0,0,0,0,0,0,0,0,0,0
    from mycte m Left Join Products p on m.[Product]=p.Product and m.State=p.State
    WHERE p.Product is null and p.State is null
    select * from Products
    Order by Product
    ,Case when State='Total' Then 2 else 1 End
    Drop table Products

Maybe you are looking for

  • Adobe acrobat pro 9 keeps telling me "the serial number I entered is not valid"

    I recently had my macbook pro logic board fail and had to purchase a new macbook pro (expensive reinvestment after only 3 years but that's another story). Anyway, all of my cs4 upsell products loaded just fine, except adobe acrobat pro 9 keeps tellin

  • Can't watch Apple 2010 keynote on macbook pro

    Hi guys. Hoping for some advice, I want to watch the streaming keynote from the apple website on my mac.. the first place you would expect seamless quicktime support. It opens the quick time app, and then is just unwatchable, whether I pic low, mediu

  • Strange editing problems in Mail

    I have been having two quirks in Mail while editing. When composing emails I sometimes send several articles from online sources such as NY Times. After copying into mail, I delete the garbage such a "print" links from the original. If I do not selec

  • Adobe Reader XI installed but "Not Found"

    I have Adobe Reader XI installed and apparently running normally. Unfortunately the UK's Parcelforce web-site says it can't find it. I get the message " Adobe Acrobat NOT found. You must have Adobe Reader (5 or better) with the browser plugin properl

  • What happens if i havent backed up my phone on itunes since 2012

    I want to update my phones software but I need to free up some storage first. So I want to back it up onto my iTunes or icloud. But since I haven't backed up this device yet I am scared everything on my phone may get deleted off of it. I am unsure of