Compare date ranges in two tables

Hello,
I'm trying to figure out a way of comparing the range of dates between two date columns from a single row in one table, to the range of dates from multiple rows in a related table.
t1 (t1_id, absent_start_date, absent_stop_date)
t2 (t2_id, t1_id, cover_start_date, cover_end_date)
t2 has multiple rows for each row in t1
I need to select rows from t1, in which the set of days for rows in t2 do not match the set of days between absent_start_date and absent_stop_date.
For example, assume this row in t1:
1, '10/08/2007', '15/08/2007'
The set of days would be 10/08/07,11/08/07,12/08/07,13/08/07,14/08/07,15/08/07
and these rows in t2
1, 1, '10/08/2007', '11/08/2007'
2, 1, '12/08/2007', '12/08/2007'
3, 1, '14/08/2007', '15/08/2007'
The set of days would be 10/08/07,11/08/07,12/08/07,14/08/07,15/08/07
In this case, the related rows in t2 do not cover the same date range as the master row in t1, and so I need to select this row from t1 somehow.
Any ideas anyone?
Thanks.

I am not sure about the exact output you want, but the next query will give you all gaps in the periods, so the presence of a row in this output may be enough?
SQL> create table t1
  2  as
  3  select 1 t1_id, date '2007-08-10' absent_start_date, date '2007-08-15' absent_stop_date from dual union all
  4  select 2, date '2007-09-01', date '2007-09-10' from dual
  5  /
Tabel is aangemaakt.
SQL> create table t2
  2  as
  3  select 1 t2_id, 1 t1_id, date '2007-08-10' cover_start_date, date '2007-08-11' cover_stop_date from dual union all
  4  select 2, 1, date '2007-08-12', date '2007-08-12' from dual union all
  5  select 3, 1, date '2007-08-14', date '2007-08-15' from dual union all
  6  select 4, 2, date '2007-09-03', date '2007-09-05' from dual union all
  7  select 5, 2, date '2007-09-07', date '2007-09-08' from dual
  8  /
Tabel is aangemaakt.
SQL> select  *
  2    from ( select t2.t1_id
  3                , lag(t2.end_date+1,1,t1.absent_start_date) over (partition by t2.t1_id order by t2.start_date) gap_start_date
  4                , t2.start_date-1 gap_end_date
  5             from t1
  6                , ( select t1_id
  7                         , cover_start_date start_date
  8                         , cover_stop_date end_date
  9                      from t2
10                     union all
11                    select t1_id
12                         , absent_stop_date+1
13                         , absent_stop_date+1
14                      from t1
15                  ) t2
16            where t1.t1_id = t2.t1_id
17         )
18   where gap_start_date <= gap_end_date
19   order by t1_id
20       , gap_start_date
21  /
                                 T1_ID GAP_START_DATE      GAP_END_DATE
                                     1 13-08-2007 00:00:00 13-08-2007 00:00:00
                                     2 01-09-2007 00:00:00 02-09-2007 00:00:00
                                     2 06-09-2007 00:00:00 06-09-2007 00:00:00
                                     2 09-09-2007 00:00:00 10-09-2007 00:00:00
4 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • How can I make my query to compare only columns of two tables... not the storage information?

    11GR2
    =-----------------------------------
    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    begin
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'PRETTY', TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE', FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',FALSE);
    DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS_AS_ALTER',FALSE);
    End;
    select REGEXP_REPLACE(dbms_metadata_diff.compare_alter('TABLE','TABLE_NAME_A','TABLE_NAME_A','USER1','USER2'),('USER1...'),'', 1, 0, 'i') from dual

    I am using below querry to compare two table that has same name, under two different users... But after making storage information false like below and  if the storage information is different on column level than it create "Alter modify " statements for the column ... How can I make my query to compare only columns of two tables... not the storage information?
    If you want help you have to SHOW us what you are doing and how you are doing it; you can't just try to tell us in your own words.
    We can't see your computer screen.

  • Date range using dual table

    I want to get the range of two date(two variables: e_date and s_date) in a proc code. Or I want to ensure the date range must be less than 180 days.
    I used: "SELECT to_date(:e_date1, 'DDMONYY') - to_date(:s_date1, 'DDMONYY') INTO :count FROM DUAL;" and "if (count <= 180)" in a proc code.
    I don't know whether there is some risks in that? Thanks.

    BluShadow wrote:
    EdStevens wrote:
    bill wrote:
    "There's a risk in using 2-digit years. Use 4-digit years to reduce errors."
    Because I only want to get the date range of two date(using :sdate and :edate variables), in anther words the relative value of two days, I think that 2 digits for the year part is permitted. Isn't it? Thanks.I can't believe Y2K was only 12 years ago and we are already forgetting the lessons.
    I few years ago (even closer to Y2k) I was in a conversation with a young programmer who expressed the opinion that Y2K was just a big hoax. After all, none of the bad things predicted really happened. I had to inform him that had he been around in 1998 and 1999 (I think he was in junior high at the time) he would have seen that the reason "nothing happened" is because armies of people like me spent two years working our a**** off to make sure nothing happened.Yep.... I was there too... checking...re-working...testing... just to ensure that everything went ok. I even had to go in and check all the servers on New Years day (oh, yes I made sure I got paid well for that one!) to make sure they were all still up and running. Only one server had a slight issue, but it was an oldie and not fixable and not a major issue.
    Yeah, me too. Sat in the server room all night watching the server light blink :-)
    Please, do yourself and your colleagues a favor and banish from your brain the entire concept of 2-digit years. When "modern" data processing got started, data records were limited to an 80-column punch card. We no longer have those constraints.4 digit years all the time.... oh yeah!You're just burying your head in the sand. It's time to start thinking about the Y10K problem, assuming we get through Dec. 21 :-)
    John

  • How to insert the data if the data in the two tables doesn't match.

    Hi,
    I have requirement like,I have to insert the data by comparing the two tables based on the date field.If they both are equal then the data shouldn't be inserted if not the data has to be inserted.
    Can some one help me on this ASAP.
    Regards,
    Sudha
    sudha

    Hi,
    Thanks for the reply,i would like to know the way that we can design the packages
    sudha
    You have multiple ways of implementing this
    1. Using Lookup Task
    http://www.sqlis.com/sqlis/post/Get-all-from-Table-A-that-isnt-in-Table-B.aspx
    2. using SCD wizard
    http://www.bimonkey.com/2009/07/the-slowly-changing-dimension-transformation-part-1/
    3. using hashing
    http://visakhm.blogspot.in/2014/06/ssis-tips-implementing-scd.html
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to Compare Data length of staging table with base table definition

    Hi,
    I've two tables :staging table and base table.
    I'm getting data from flatfiles into staging table, as per requirement structure of staging table and base table(length of each and every column in staging table is 25% more to dump data without any errors) are different for ex :if we've city column with varchar length 40 in staging table it has 25 in base table.Once data is dumped into staging table I want to compare actual data length of each and every column in staging table with definition of base table(data_length for each and every column from all_tab_columns) and if any column differs length I need to update the corresponding row in staging table which also has a flag called err_length.
    so for this I'm using cursor c1 is select length(a.id),length(a.name)... from staging_table;
    cursor c2(name varchar2) is select data_length from all_tab_columns where table_name='BASE_TABLE' and column_name=name;
    But we're getting data atonce in first query whereas in second cursor I need to get each and every column and then compare with first ?
    Can anyone tell me how to get desired results?
    Thanks,
    Mahender.

    This is a shot in the dark but, take a look at this example below:
    SQL> DROP TABLE STAGING;
    Table dropped.
    SQL> DROP TABLE BASE;
    Table dropped.
    SQL> CREATE TABLE STAGING
      2  (
      3          ID              NUMBER
      4  ,       A               VARCHAR2(40)
      5  ,       B               VARCHAR2(40)
      6  ,       ERR_LENGTH      VARCHAR2(1)
      7  );
    Table created.
    SQL> CREATE TABLE BASE
      2  (
      3          ID      NUMBER
      4  ,       A       VARCHAR2(25)
      5  ,       B       VARCHAR2(25)
      6  );
    Table created.
    SQL> INSERT INTO STAGING VALUES (1,RPAD('X',26,'X'),RPAD('X',25,'X'),NULL);
    1 row created.
    SQL> INSERT INTO STAGING VALUES (2,RPAD('X',25,'X'),RPAD('X',26,'X'),NULL);
    1 row created.
    SQL> INSERT INTO STAGING VALUES (3,RPAD('X',25,'X'),RPAD('X',25,'X'),NULL);
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> SELECT * FROM STAGING;
            ID A                                        B                                        E
             1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX
             2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX
             3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXX
    SQL> UPDATE  STAGING ST
      2  SET     ERR_LENGTH = 'Y'
      3  WHERE   EXISTS
      4          (
      5                  WITH    columns_in_staging AS
      6                  (
      7                          /* Retrieve all the columns names for the staging table with the exception of the primary key column
      8                           * and order them alphabetically.
      9                           */
    10                          SELECT  COLUMN_NAME
    11                          ,       ROW_NUMBER() OVER (ORDER BY COLUMN_NAME) RN
    12                          FROM    ALL_TAB_COLUMNS
    13                          WHERE   TABLE_NAME='STAGING'
    14                          AND     COLUMN_NAME != 'ID'
    15                          ORDER BY 1
    16                  ),      staging_unpivot AS
    17                  (
    18                          /* Using the columns_in_staging above UNPIVOT the result set so you get a record for each COLUMN value
    19                           * for each record. The DECODE performs the unpivot and it works if the decode specifies the columns
    20                           * in the same order as the ROW_NUMBER() function in columns_in_staging
    21                           */
    22                          SELECT  ID
    23                          ,       COLUMN_NAME
    24                          ,       DECODE
    25                                  (
    26                                          RN
    27                                  ,       1,A
    28                                  ,       2,B
    29                                  )  AS VAL
    30                          FROM            STAGING
    31                          CROSS JOIN      COLUMNS_IN_STAGING
    32                  )
    33                  /*      Only return IDs for records that have at least one column value that exceeds the length. */
    34                  SELECT  ID
    35                  FROM
    36                  (
    37                          /* Join the unpivoted staging table to the ALL_TAB_COLUMNS table on the column names. Here we perform
    38                           * the check to see if there are any differences in the length if so set a flag.
    39                           */
    40                          SELECT  STAGING_UNPIVOT.ID
    41                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_A
    42                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_B
    43                          FROM    STAGING_UNPIVOT
    44                          JOIN    ALL_TAB_COLUMNS ATC     ON ATC.COLUMN_NAME = STAGING_UNPIVOT.COLUMN_NAME
    45                          WHERE   ATC.TABLE_NAME='BASE'
    46                  )       A
    47                  WHERE   COALESCE(ERR_LENGTH_A,ERR_LENGTH_B) IS NOT NULL
    48                  AND     ST.ID = A.ID
    49          )
    50  /
    2 rows updated.
    SQL> SELECT * FROM STAGING;
            ID A                                        B                                        E
             1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX                Y
             2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX               Y
             3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXHopefully the comments make sense. If you have any questions please let me know.
    This assumes the column names are the same between the staging and base tables. In addition as you add more columns to this table you'll have to add more CASE statements to check the length and update the COALESCE check as necessary.
    Thanks!

  • One table in ms access----- data migration ----- oracle two tables

    Hi,
    we are try to migrate from ms access to oracle.
    Ms access has patient table
    PATIENT_FNAME
    PATIENT_LNAME
    PATIENT_MNAME
    PATIENT_ADDRESS1
    PATIENT_ADDRESS2
    PATIENT_ADDRESS3
    PATIENT_SUBURB
    PATIENT_STATE
    PATIENT_POSTCODE
    PATIENT_COUNTRY
    PATIENT_PHONE
    PATIENT_MOBILE
    PATIENT_SEX
    PATIENT_DOB
    DIAGNOSIS_REV
    RECEIVED_THAL
    RECEIVED_STC
    RECEIVED_BORTEZOMIB
    DIAGNOSIS_OTHER
    DIAGNOSIS_THAL
    DIAGNOSIS_THAL_RR_MM
    DIAGNOSIS_THAL_UNTREATED_MM
    DIAGNOSIS_THAL_ENL
    DIAGNOSIS_THAL_NONAPPROVED
    DIAGNOSIS_THAL_OTHER
    PRESCRIBER_ID foreign key
    PRESCRIBER_FNAME
    PRESCRIBER_LNAME
    PRESCRIBER_MNAME
    PRESCRIBER_ADDRESS1
    PRESCRIBER_ADDRESS2
    PRESCRIBER_ADDRESS3
    PRESCRIBER_DEPARTMENT
    PRESCRIBER_ATTENTION
    PRESCRIBER_SUBURB
    PRESCRIBER_STATE
    PRESCRIBER_POSTCODE
    PRESCRIBER_COUNTRY
    PRESCRIBER_PHONE
    PRESCRIBER_FAX
    DATE_PRESCRIBER_SIGNED
    DATE_PATIENT_SIGNED
    DATE_APPROVED
    DATE_RECEIVED
    PROCESSED_BY
    PATIENT_ID primary key
    COMMENTS
    UPIN
    SIGNED_BY
    PATIENT_REP_NAME
    IACCESS_STATUS
    PRESCRIBER_RN
    QUESTION_1
    QUESTION_2
    QUESTION_3
    QUESTION_4
    QUESTION_5
    QUESTION_6
    QUESTION_7
    QUESTION_8
    QUESTION_9
    QUESTION_10
    QUESTION_11
    QUESTION_12
    PRESCRIBER_SIGNED
    NOTIFICATION_UPIN
    WOCBP
    FOLLOWUP_REQUIRED
    FOLLOWUP_NOTES
    FOLLOWUP_STATUS
    REV_THAL
    DATE_DEACTIVATED
    DEACTIVATE_REASON
    VERIFIED
    VERIFIED_BY
    REGISTERED_REVLIMID
    REGISTERED_THALIDOMIDE
    FILE_NAME
    In oracle  they divieded into two tables
    SQL> desc tbl_patient
    Name
    PATIENT_ID primary key
    PATIENT_NAME_FIRST
    PATIENT_NAME_LAST
    PATIENT_MIDDLE_INITIAL
    PATIENT_GENDER
    PATIENT_DOB
    SQL> desc tbl_patient_prescriber
    Name
    PATIENT_ID foreign key
    PRESCRIBER_ID primary key
    PRESCRIBER_NAME_FIRST
    PRESCRIBER_NAME_LAST
    PRESCRIBER_MIDDLE_INITIAL
    First i can load the datas into tbl_patient.
    How to insert the datas to tbl_patient_prescriber If it's null values and repeated values are there in ms access or staging table.

    I am seeing, perhaps three tables here.
    Patient -
    Patient_id (PK)
    first_name,
    last_name,
    Other attributes
    Prescriber -
    Prescriber_id (PK)
    first_name,
    last_name
    Other attributes
    Patient_prescriber -
    Patient_id (FK-PK)
    Prescriber_id (FK-PK)
    meds_order_id (PK)
    Other patient_prescriber attributes.

  • Neen help with date range searches for Table Sources

    Hi all,
    I need help, please. I am trying to satisfy a Level 1 client requirement for the ability to search for records in crawled table sources by a date and/or date range. I have performed the following steps, and did not get accurate results from Advanced searching for date. Please help me understand what I am doing wrong, and/or if there is a way to define a date search attribute without creating a LOV for a date column. (My tables have 500,00 rows.)
    I am using SES 10.1.8.3 on Windows 32.
    My Oracle 10g Spatial Table is called REPORTS and this table has the following columns:
    TRACKNUM Varchar2
    TITLE Varchar2
    SUMMARY CLOB
    SYMBOLCODE Varchar2
    Timestamp Date
    OBSDATE Date
    GEOM SDO_GEOMETRY
    I set up the REPORTS table source in SES, using TRACKNUM as the Primary Key (unique and not null), and SUMMARY as the CONTENT Column. In the Table Column Mappings I defined TITLE as String and TITLE.
    Under Global Settings > Search Attributes I defined a new Search Attribute (type Date) called DATE OCCURRED (DD-MON-YY).
    Went back to REPORTS source previously defined and added a new Table Column Mapping - mapping OBSDATE to the newly defined DATE OCCURRED (DD-MON-YY) search attribute.
    I then modified the Schedule for the REPORTS source Crawler Policy to “Process All Documents”.
    Schedule crawls and indexes entire REPORTS table.
    In SES Advanced Search page, I enter my search keyword, select Specific Source Group as REPORTS, select All Match, and used the pick list to select the DATE OCCURRED (DD-MON-YY) Attribute Name, operator of Greater than equal, and entered the Value 01-JAN-07. Then the second attribute name of DATE_OCCURRED (DD-MON-YY), less than equals, 10-JAN-07.
    Search results gave me 38,000 documents, and the first 25 I looked at had dates NOT within the 01-JAN-07 / 10-JAN-07 range. (e.g. OBSDATE= 24-MAR-07, 22-SEP-), 02-FEB-08, etc.)
    And, none of the results I opened had ANY dates within the SUMMARY CLOB…in case that’s what was being found in the search.
    Can someone help me figure out how to allow my client to search for specific dated records in a db table using a single column for the date? This is a major requirement and they are anxiously awaiting my solution.
    Thanks, in advance….

    raford,
    Thanks very much for your reply. However, from what I've read in the SES Admin Document is that (I think) the date format DD/MM/YYYY pertains only to searches on "file system" sources (e.g. Word, Excel, Powerpoint, PDF, etc.). We have 3 file system sources among our 25 total sources. The remaining 22 sources are all TABLE or DATABASE sources. The DBA here has done a great job getting the data standardized using the typical/default Oracle DATE type format in our TABLE sources (DD-MON-YY). Our tables have anywhere from 1500 rows to 2 million rows.
    I tested your theory that the dates we are entering are being changed to Strings behind the scenes and on the Advanced Page, searched for results using OBSDATE equals 01/02/2007 in an attempt to find data that I know for certain to be in the mapped OBSDATE table column as 01-FEB-07. My result set contained data that had an OBSDATE of 03-MAR-07 and none containing 01-FEB-07.
    Here is the big issue...in order for my client to fulfill his primary mission, one of the top 5 requirements is that he/she be able to find specific table rows that are contain a specific date or range of dates.
    thanks very much!

  • Need help with date range searches for Table Sources in SES

    Hi all,
    I need help, please. I am trying to satisfy a Level 1 client requirement for the ability to search for records in crawled table sources by a date and/or date range. I have performed the following steps, and did not get accurate results from Advanced searching for date. Please help me understand what I am doing wrong, and/or if there is a way to define a date search attribute without creating a LOV for a date column. (My tables have 500,00 rows.)
    I am using SES 10.1.8.3 on Windows 32.
    My Oracle 10g Spatial Table is called REPORTS and this table has the following columns:
    TRACKNUM Varchar2
    TITLE Varchar2
    SUMMARY CLOB
    SYMBOLCODE Varchar2
    Timestamp Date
    OBSDATE Date
    GEOM SDO_GEOMETRY
    I set up the REPORTS table source in SES, using TRACKNUM as the Primary Key (unique and not null), and SUMMARY as the CONTENT Column. In the Table Column Mappings I defined TITLE as String and TITLE.
    Under Global Settings > Search Attributes I defined a new Search Attribute (type Date) called DATE OCCURRED (DD-MON-YY).
    Went back to REPORTS source previously defined and added a new Table Column Mapping - mapping OBSDATE to the newly defined DATE OCCURRED (DD-MON-YY) search attribute.
    I then modified the Schedule for the REPORTS source Crawler Policy to “Process All Documents”.
    Schedule crawls and indexes entire REPORTS table.
    In SES Advanced Search page, I enter my search keyword, select Specific Source Group as REPORTS, select All Match, and used the pick list to select the DATE OCCURRED (DD-MON-YY) Attribute Name, operator of Greater than equal, and entered the Value 01-JAN-07. Then the second attribute name of DATE_OCCURRED (DD-MON-YY), less than equals, 10-JAN-07.
    Search results gave me 38,000 documents, and the first 25 I looked at had dates NOT within the 01-JAN-07 / 10-JAN-07 range. (e.g. OBSDATE= 10-MAR-07, 22-SEP-07, 02-FEB-08, etc.)
    And, none of the results I opened had ANY dates within the SUMMARY CLOB…in case that’s what was being found in the search.
    Can someone help me figure out how to allow my client to search for specific dated records in a db table using a single column for the date? This is a major requirement and they are anxiously awaiting my solution.
    Thanks very much, in advance….

    raford,
    Thanks very much for your reply. However, from what I've read in the SES Admin Document is that (I think) the date format DD/MM/YYYY pertains only to searches on "file system" sources (e.g. Word, Excel, Powerpoint, PDF, etc.). We have 3 file system sources among our 25 total sources. The remaining 22 sources are all TABLE or DATABASE sources. The DBA here has done a great job getting the data standardized using the typical/default Oracle DATE type format in our TABLE sources (DD-MON-YY). Our tables have anywhere from 1500 rows to 2 million rows.
    I tested your theory that the dates we are entering are being changed to Strings behind the scenes and on the Advanced Page, searched for results using OBSDATE equals 01/02/2007 in an attempt to find data that I know for certain to be in the mapped OBSDATE table column as 01-FEB-07. My result set contained data that had an OBSDATE of 03-MAR-07 and none containing 01-FEB-07.
    Here is the big issue...in order for my client to fulfill his primary mission, one of the top 5 requirements is that he/she be able to find specific table rows that are contain a specific date or range of dates.
    thanks very much!

  • Generate delta records by comparing multiple fields from two tables?

    I have two tables with similar fields. Let's say Table 1 (T1) has fields Customer, A, B and C. Table 2 (T2) has fields Customer0002, A0002, B0002 and C0002. For each customer (each record) I want to check whether there is any difference in field A and A0002 or B and B0002 or C and C0002. If there is a difference between any of these pairs of fields then I will update that customer's record. Currently I have a piece of code
       DATA: ls_source TYPE y_source_fields,
            ls_target TYPE y_target_fields.
      LOOP AT it_source INTO ls_source.
        if not ( ls_source-A = ls_source-A0002 ).
          MOVE-CORRESPONDING ls_source TO ls_target.
          APPEND ls_target TO et_target.
        endif.
      ENDLOOP.
    This checks for the difference between one pair - A and A0002. How can I make it check 3 pairs and update when any of them have differences?

    Hello Khaled
    Why don't you add  B and B0002 - C and C0002 fields into your if declaration?
    LOOP AT it_source INTO ls_source.
        if not (
    ls_source-A = ls_source-A0002 and
    ls_source-B = ls_source-B0002 and
    ls_source-C = ls_source-C0002
          MOVE-CORRESPONDING ls_source TO ls_target.
          APPEND ls_target TO et_target.
        endif.
      ENDLOOP.
    I think you have more than 3 fields and the count of these fields are dynamic right?
    Do you about the ASSIGN COMPONENT x OF STRUCTURE y TO <field_symbol>.  usage?
    Can you explain your need in detail please.
    Edited by: Bulent Balci on Jul 27, 2010 4:18 PM

  • Data fetch from two table without refresh

    hi Friends,
    I have a problem i want to extract data from two table without refresh into text field when i'll enter any value in a text field then corressponding value should come in to corressponding textfield.
    eg. there two table A and B.
    Table A has Colunm
    s_id Number;
    c_id Varchar2(30);
    sec varchar2(4);
    Second Table B Colunm Name
    s_id Number;
    f_name varchar(30);
    l_name varchar(20);
    when i enter s_id 101 in a text field then the c_id ,sec,first_name and last_name should come in to corressponding text fields without refresh.
    How Can I do this.
    Thanks
    Manoj

    Hi Manoj,
    You have to make an Ajax call to display data without refreshing the page. Search this forum for Ajax and you can find lots of related posts. This link might help too. http://www.dba-oracle.com/t_html_db_apex_ajax_application_express.htm
    Thanks,
    Manish.

  • Split date range without Calendar table

    Hi guys!
    Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?
    Reason I'm asking this is because we have a huge Fact table (500+ million records) and joining small Calendar table and this huge Fact table takes considerable amount of time.
    So far we tried:
    Join 2 tables (Fact and Calendar)
    Cross Applying Calendar and table-valued function (that returns necessary measures from Fact table)
    and both approaches took few minutes for 1 day to complete.
    Most successful test we had so far was using CLR and executing table-valued functions in parallel for different 15 minute periods. This way we were able to get the results in 3-4 seconds.
    Anyway, is there any effective pure T-SQL way to accomplish this?
    Thanks in advance,
    Miljan

    Try using a temporary table rather than table variable.. You can have a CI on the date column.
    or
    declare @PeriodStart datetime2(0) = '2013-01-05 00:00:00'
    declare @PeriodEnd datetime2(0) = '2013-01-05 02:00:00'
    select T.PeriodStart, T.PeriodEnd, count(Column1)as count1, sum(Column2)as sum1
    from Fact F with(nolock)WHERE F.[Start]>= '19000101' AND <=@PeriodStartand F.[End] >= @PeriodEnd and F.[End] <='20200101'
    group by T.PeriodStart, T.PeriodEnd
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Can we create a BAM data Object from two tables

    Hi ,
    I want to pull the data from two tables and create a BAM data object, Is it possible in BAM?
    Do the needful
    Regards,
    Francis

    The sample way is using AQ on database. You can create a database view to join the tables. And create AQ on the view, create a ems to listen on the queue.

  • How to guarantee data consistency in two tables

    Hi
    I have two tables debits and credits:
    create table debits
    client_id number;
    amount_debit number
    create table credits
    client_id number;
    amount_credit number
    Now I need to guarantee that sum(amount_debit) - sum(amount_credit) > 0 for a specific client. Now I created a trigger on the credit table:
    TRIGGER DEBIT_TRIGGER BEFORE INSERT ON "PPC"."DEBIT"
    REFERENCING OLD AS OLD NEW AS NEW
    FOR EACH ROW
    declare
    v_amount_debit number;
    v_amount_credit number;
    begin
    select sum(amount_debit)
    into v_amount_debit
    from debit
    where client_id = :new.client_id;
    select sum(amount_credit)
    into v_amount_credit
    from credit
    where client_id = :new.client_id;
    if (v_amount_debit - v_amount_credit) < 0 then
    raise_application_error(-20005, 'Error');
    end if;
    end;
    But this won't work with multiple sessions because in two separates sessions an account can go below 0 before commit and the trigger won't detect the error.
    In this case how can I guarantee data consistency?

    You could SELECT...FOR UPDATE on the related row (in the "clients" table?) referenced by client_id, but...
    1. Do you also need UPDATE and DELETE triggers on the "debits" table? How would you prevent an update of a debit (or a delete of a negative "debit) that causes the balance to drop below zero?
    2. Do you also need (INSERT, UPDATE, and DELETE triggers) on the "credits" table? How would you prevent a delete or update of a credit (or an insert of a negative "credit") that causes the balance to drop below zero?
    3. It might be easier to use a "refresh on commit" materialized view to enforce the constraint, something along the lines of the discussion at:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:21389386132607
    4. Another alternative might be to revoke insert, update, and delete privileges on the two tables and instead provide stored procedures (maybe named "debit" and "credit") that provide the necessary functionality and enforce the constraints (with locking).
    Hope this helps.

  • How to compare record count of two tables?

    Hi,
    i am in need of simple sql script where i can compare two table record count.
    i have something like below:
    (select count(*) from table1) minus (select count(*) from table2)
    now the problem is if the table1 count greater then table2 count the output is fine.
    If the table2 record count is more then i am getting zero as the output.
    how can i get the difference in two tables record count?
    Thanks a lot in advance.
    --Raman.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Doing a MINUS between the counts does not yield the diff.
    e.g. if table A has 100 records and table B has 70 records then,
    SELECT count(*) FROM A
    minus
    SELECT count(*) from B
    will give 100 and not 30.
    Try this:
    SELECT (
    CASE WHEN ((select count(*) cnt from A) - (select count(*) cnt from B)) <0
    THEN ((select count(*) cnt from A) - (select count(*) cnt from B))* -1
    ELSE ((select count(*) cnt from A) - (select count(*) cnt from B)) END) Difference
    FROM dualor this is simpler
    SELECT abs(((select count(*) cnt from A) - (select count(*) cnt from B))) difference FROM dualEdited by: Caitanya on Jan 9, 2009 7:12 AM
    Applied abs function after seeing BluShadow's post :)

  • How to compare date range ?

    hi, good day , i need some idea on my issue
    scenario :
    i need to know if given a new date range, and check whether this new date range is fall into between the date range
    for example ,
    new_start_date = 15/05/2006, new_end_date = 01/09/2006
    existing start_date = 20/02/2006 , existing end_date = 11/07/2006 so in this case , new start and end date have fall into existing start and end date range, cause it should not interlapse the date range
    - in short, new start_date and end_date cannot in between of existing start_date and end_date , how i write a algorithm on this ? thank you for guidance

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    * DateSample.java
    * Created on February 9, 2006, 10:09 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    * @author krichard
    public class DateSample {
         *  new_start_date = 15/05/2006, new_end_date = 01/09/2006
         *  existing start_date = 20/02/2006 , existing end_date = 11/07/2006
        /** Creates a new instance of DateSample */
        public DateSample() {
            String existingStartDateStr = "20/02/2006" ;
            String existingEndDateStr = "11/07/2006" ;
            String newStartDateStr = "15/05/2006" ;
            String newEndDateStr = "01/09/2006" ;
            SimpleDateFormat dateUtil = new SimpleDateFormat("dd/MM/yyyy") ;
            try {
                Date existingStartDate = dateUtil.parse(existingStartDateStr);
                Date existingEndDate = dateUtil.parse(existingEndDateStr);
                Date newStartDate = dateUtil.parse(newStartDateStr);
                Date newEndDate = dateUtil.parse(newEndDateStr);
                boolean newStartCheck = existingStartDate.before(newStartDate) && existingEndDate.after(newStartDate);
                boolean newEndCheck = existingStartDate.before(newEndDate) && existingEndDate.after(newEndDate);
                boolean inBetween = newStartCheck & newEndCheck ;
                System.out.println("Existing::"+existingStartDate+" - " +existingEndDate);
                System.out.println("New::"+newStartDate+" - " +newEndDate);
                System.out.println("It is "+inBetween+" that the new dates are in between the existing ones.");
            } catch (ParseException ex) {
                ex.printStackTrace();
         * @param args the command line arguments
        public static void main(String[] args) {
            new DateSample() ;
    }

Maybe you are looking for