Conditional merge based on date

Need help on a merge statement. I need to merge two dataset. But when the key match , I also need to cpmpared the date before I merege it.
See code below
drop table x1;
drop table y1;
select * from x1;
select * from y1;
create table x1 (id number,name varchar2(10),cdate date,status varchar2(1));
create table y1 (id number,name varchar2(10),cdate date,status varchar2(1));
insert into x1 select 1,'A',sysdate - 100,'Y' from dual;
insert into y1 select 1,'A',sysdate - 50,'N'  from dual ;--should change x1.status to y1.status  and x1.cdate to y1.cdate as y1.cdate > x1.cdate
insert into x1 select 2,'B',sysdate - 20,'Y' from dual;
insert into y1 select 2,'B',sysdate - 120,'N' from dual ;--should leave status in x1 alone
insert into y1 select 3,'c',sysdate - 10,'Y' from dual; --should do an insert on x1
commit;
--how do I do a conditional merge (key=id,name)
-- based on the cdate. If y1.cdate >= x1.cdate then take the y1.status  and y1.cdate
--desire output
select * from x1
1     A     01/01/2012 10:54:35 AM     N
2     B     1/31/2012 10:54:37 AM     Y
3     C     1/31/2012 10:54:37 AM     Y

Hi,
You can add a WHERE clause to the WHEN MATCHED THEN UPDATE section.
WHERE   x1.cdate  < y1.cdateThanks for posting the CREATE TABLE and INSERT statements; that's very helpful. It would also be helpful if you posted your MERGE statement, even if it's not working perfectly.

Similar Messages

  • Conditional format based on date

    Hi,
    I want to keep track of reports that my students need to turn in. The due date is set, but should turn red 10 days before the actual due date, so I can double check with the student if he started work on his report. Once the report was turned in, the due date should become grey or black. Here's an example:
    Report
    Topic
    Due date
    Finished
    A
    XX
    Jan 26, 2012
    Jan 25, 2012
    B
    YY
    Feb 5, 2012
    C
    ZZ
    Mrz 11, 2012
    C3 is read, because its due date is less than 10 days away. C2 is black, because it has been finished on time. C4 is black, because its due date is more than 10 days away (from the perspective of today, Jan. 27th)
    While conditional formats can be set based on dates and relative dates, it doesen't allow to compare actual date to a date calculated from a cell, as far as I can see.
    Any help with this is very appreciated!
    Thank you!

    Maybe this sample may fit your needs :
    One more case where Numbers User Guide is helpful.
    Yvan KOENIG (VALLAURIS, France) vendredi 27 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My Box account  is : http://www.box.com/s/00qnssoyeq2xvc22ra4k

  • Select Query Based on date condition

    Hi ,
    Is it Possible.
    i want to run select query based on date condition.
    Eg...
    if the date between 01-jan-01 and 01-jan-05 then
    select * from table1;
    if the date between 02-jan-05 and 01-jan-08 then
    select * from table2;
    Becaz i have data in 2 diffrent tables , based on the date condition i wnt to run the select statement to diffrent tables.
    i dont want plsql here Just SQL needed.
    thanks,
    -R
    Edited by: infant_raj on May 5, 2009 11:48 PM

    Helo Kanish,
    this is not the one i was asking..
    wht i mean was .
    i use bind variable to get date while running the select statement , once i get the date then i want to choose any one of the table to run select query.
    EG..
    select col1,col2 from table1 where date between only if 01-jan-01 and 01-jan-05;
    select col1,col2 from table2 where date between only if 02-jan-05 and 01-jan-08;
    Run any one of the two . not all
    thanks,
    _raj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to build conditional text from a data merge

    Hi there
    I'm hoping this is not a long shot but I do have a rather large ask (I think). 
    I cannot figure out how to create conditions on values.
    We have two areas that require conditional text. See these areas on the attached image. 
    Features offered - up to 6.  These are identified by defining each feature with a letter, eg 'n' stands for tent site and 'L' stands for seasonal work,  and
    Room type offered - four colour codes with this. These range from "not made up", "made up", "ensuite/madeup" and "ensuite".
    The tab delimited file contains numerous columns for each room type - single, double, twin, share and dorm rooms that offer the 4 room type categories - see point 2 above. 
    I cannot figure out how to clarify the conditions I require for the conditional text.
    Do I start with making 4 conditions for each room type colour and so-on for the rest of the room types ie single not madeup, single madeup, single madeup ensuite and single ensuite? 
    And if so, how do I create these using the correct conditional code?   Does GREP have anything to do with this and do I need to use its metacharacters like \?
    Can someone perhaps start me off?
    The same goes for the features.  The features are displayed in the spreadsheet per column with either a 'yes' or a 'no' displayed.
    I hope I have provided enough information to get some assistance.
    Thanks so much.

    Tag Design wrote:
    Hi there
    I'm hoping this is not a long shot but I do have a rather large ask (I think). 
    I cannot figure out how to create conditions on values.
    We have two areas that require conditional text. See these areas on the attached image. 
    Features offered - up to 6.  These are identified by defining each feature with a letter, eg 'n' stands for tent site and 'L' stands for seasonal work,  and
    Room type offered - four colour codes with this. These range from "not made up", "made up", "ensuite/madeup" and "ensuite".
    The tab delimited file contains numerous columns for each room type - single, double, twin, share and dorm rooms that offer the 4 room type categories - see point 2 above. 
    I cannot figure out how to clarify the conditions I require for the conditional text.
    Do I start with making 4 conditions for each room type colour and so-on for the rest of the room types ie single not madeup, single madeup, single madeup ensuite and single ensuite? 
    And if so, how do I create these using the correct conditional code?   Does GREP have anything to do with this and do I need to use its metacharacters like \?
    Can someone perhaps start me off?
    The same goes for the features.  The features are displayed in the spreadsheet per column with either a 'yes' or a 'no' displayed.
    I hope I have provided enough information to get some assistance.
    Thanks so much.
    Maybe I'm missing something, but I can't see why you need conditional text. I can see that you may want to color each property in each category differently, to stand out for quick visual communication.
    If each feature (attribute) of each property or venue is represented in one spreadsheet row (record,) you can use data merge to create the whole entry for each property. For example, a property may offer two types of rooms - single and double, and the single may be available as "not made up" only, while the double is available as "ensuite/madeup" and "ensuite."
    In the spreadsheet, in the row for the Acme Inn property, which only offers single not-made-up and single ensuite/madeup rooms, and for the Ajax Hotel property which offers single made-up, single ensuite/madeup, and single ensuite rooms, the cells that contain the data for the merge fields would look like this:
    Property ID
    single not-made-up
    single made-up
    single ensuite/madeup
    single ensuite
    Acme Inn
    $50
    empty cell
    $75
    empty cell
    Ajax Hotel
    empty cell
    $65
    $75
    $85
    On the data-merge layout, each room type's label would be followed by all four data-merge field placeholders, with colors applied, so the single would look like:
    Sgle: <<single not-made-up>> (red) <<made-up>> (yellow) <<ensuite/madeup>> (green) <<ensuite>> (blue)
    NOTE: The colors are applied with named character styles to the data-merge layout in InDesign.
    [EDIT] BAH! I applied colors to the text when composing this post, but they were removed when I posted. [/EDIT]
    When you set up the merge with Remove Blank Lines for Empty Fields enabled (checked) so the empty cells are ignored, the result resembles this:
    For the Acme Inn:      Sgl: $50 (red) $75 (green) $85 (blue)
    For the Ajax Hotel:    Sgl: $65 (yellow) $75 (green) $85 (blue)
    The separator character between the prices in your example is a special issue. It could be solved in the spreadsheet by creating calculated columns between the price columns, with "IF" formulas that test for values or empty cells and display the separator or nothing. If you choose this method, you'd need to insert fields between the placeholder fields, to hold the calculated fields' contents.
    Another approach here would be to follow the data-merge process with a GREP script that inserts separators where they're needed.
    Search Google for terms like "InDesign data-merge tutorial," "InDesign data-merge remove blank lines," "InDesign multiple records per page," and similar phrases without quotes.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices
    Message was edited by: peter at knowhowpro

  • Hide Repeating Frames based on data value

    Hello,
    Wonderful forum. Hope someone out there can give us input on this one. We have a report where we would like to show a different layout depending on the data value from the master query. One layout occupies a full 8X11 page and the second layout occupies 1/3rd of a page. Is it possible to hide one reapeating frame and show the other based on data value? This would be a multiple page report and each page will have to take the correct payout depending on the value of the data in the row.
    I appreciate any input on this. Thanks
    Ravi

    Thanks for you input. I appreciate it.
    I am having a problem doing this. Let us say i have 2 differnt paper layouts. I want to show or hide one of the layouts based on a data value.
    The problem i am facing is that the 2nd instance of true value for showing the 1st layout is over lapping the 1st instance of the 2nd layout thus showing 2 layouts overlapping each other on the same page. I know this is confusing but i will attempt to give an example:
    page 1 shows - layout #1 only is showing based on result of data value. This is good.
    page 2 shows - layout #2 shows based on data value, but also the 2nd instace of layout #1 (what ever data record satisfies layout #1 rule) is also showing over layout #2. So both the layouts are jumbled up on 1 page.
    Essentially conditional formatting on layout #1 is not able to recognize that there is a 2nd layout taking its place and thus showing the layout #1 whenever it finds data which satisfies the condition on the 2nd page and so on..
    Any help is greatly appreciated.
    Thanks..

  • Selecting material based on date

    Hello Experts,
    I have requirement where i want to give material and date.
    i have to select materia, condition record number based on date.
    In database table field is stored like material , validity from date and validity to date.
    Same material number is there but validity date and condtion record number is different.
    Matno        from date                 to date                      Condition record no
    1234       01.01.2009                31.12.2009                       23456
    1234       01.01.2008                31.12.2008                       12367
    if user enter date 12.09.2009 it should fetch me first record. ( because date is between 01.01.2009 to 31.12.2009)
    if user enter date 20.08.2008 it should fetch me first record. ( because date is between 01.01.2008 to 31.12.2008)
    field for input date is fkdate.
    So how i have to query in select statement to get this requirement.
    Thanks in advance.
    Best regards,
    Sai

    select * "or the fields you need
           from abcd
            into table itab
            where matnr in s_matnr "if you have it in sel screen or remove it..
                 and dat_fr GE p_fkdat
                 and dat_to LE p_fkdat.
    but if the dates are not keys...
    better not use them in select...
    delete the unnecessary items after the select using DELETE ITAB where...

  • Conditional Merge - Survivorship in EDQ

    Hi
    i'd like to know if it is possubtle to do a "conditional merge" in EDQ so null values do not overwrite existing data.
    FOr example:
    i have an existing customer record with a date of birth and now I want to merge with additional data set coming in. I set up survivorship rules so that the newest complete record wins however the new record has a null value in date of birth. How do I accept all of the newest data records values except the DOB?
    this is typical functionality in most DQ tools but we can not find this documented in EDQ.
    Thanks
    Darren

    Darren,
    Are these "survivorship" rules defined in Siebel UCM or is this a standalone EDQ project? If the latter, then you can simply use a "Merge Attributes" processor with the "Select empty strings" options set to "No".
    regards,
    Nick

  • Condition type based on minimum order qty

    hi all,
    can anyone help me solved this problem.
    i have maintain min order qty in material master (MVKE-AUMNG) . let say 10PCS ($5/PCS). then i create Sales Order (Tcode VA01) with qty = 5, the system propose warning (we can still continue create order).
    i want to have condition type (let say ZZPR) that have value = Price * min qty --> $5 * 10 PCS.
    i think we need routine in calculation base value. can anyone know the code for this routine?
    thx
    Best Regard,
    Hendry

    hi raj,
    put routine in condition based value.
    data : zaumng type mvke-aumng.
      select single aumng into zaumng
        from mvke
        where matnr = komp-matnr and
              vkorg = komk-vkorg and
              vtweg = komk-vtweg.
    move zaumng to xkwert.
    hopefully it helps..
    Best Regard,
    Hendry

  • Data not submitting when I have a conditional display on a date field

    Hello all,
    Could someone please help me with the following issue?
    I have created an updateable report region with four updateable fields. 3 of the fields store a number values and the fourth stores a date value.
    Each updateable report item has a conditional display, and whether they are displayed or not is controlled by the end user using a radio group (with submit). This provides the user with three options.
    If I remove all conditional displays all data will commit to the database without any problems. If I apply the conditional display to the number fields only, again the data will commit as normal. However, as soon as I add a conditional display to the date field it all goes pair shaped. The data will then cease to commit, with no error message at all. Once I remove the conditional display normal service is resumed.
    I'm certainly an APEX novice at the moment, so I wondered if anyone could shed some light on this.
    Thanks in advance for your help
    Steve

    Stew,
    Basically, I have edited each applicable report field column attributes, via the report attributes tab, and selected a conditional display 'Value of item in Expression 1 = Expression 2' for all of them.
    In the same report region I have created a radiogoup with submit called p51_update_type, specifying three static return values; R, F and S
    Condition e.g.
    *"Expression 1"*
    p51_update_type
    *"Expression 2"*
    S
    All columns display as expected, and commits to the database are normal, that is until I apply a conditional display to the date field (which relates to a table column of type DATE in the database).
    Thanks
    Steve

  • Process Chain - How to make decision based on data in PSA and execute DTP

    Need to create process in Process Chain, which will execute the DTP based on data in PSA.
    Say we have two DSO A & B, both getting data from same datasource.
    In process chain, we need to read data in one of the date field in PSA and make a decision, which DTP to get execute in process chain.
    Say if date field contains year = 2000, than load to DSO A, if year is 2001, load data to DSO B.
    Suggest the solution. ...

    Hi,
    Tyr this steps.
    1) Develop ABAP process types
    ABAP report to read PSA data using function module
    Trigger events based on year
                           event1 -> for even year data
                           event2 -> for add year data
    2) Develop local process chains for each DTPs and schdule it with events mentioned above.
    Do reply with comments.

  • Batch Determination based on date of consig recieve

    Hi,
    I am getting problem when i am trying to do manual batch determination in the outbound delivery.
    I have created a record in VCH1 based on customer/Material/Plant. In this i have maintained a sort rule also. what characteristaics i must use to make my batch determination based on customer consignment recieving date?
    If i go in MSC3n with Material, Plant and batch data then in the screen ( table MCHA, MCH1) onlt data available is for ERSDA, LAEDA  and LWEDT.
    In delivery when i click on batch determination button. my Sort rule is not automatically determined. So i have to maunally entered my soirt rule but at the same time my qty proposal in the same screen is 1 which is nothing but
    FORM CHMVS_001.
      DATA: lv_line TYPE kondh-chasp VALUE '1'.
      LOOP AT disqty.
        CHECK lv_line <= no_of_split.
        IF QUAN_TO_DIS > 0.
          IF DISQTY-AVAL_QUAN > QUAN_TO_DIS.
            DISQTY-QUANTITY = QUAN_TO_DIS.
          ELSEIF disqty-aval_quan > 0.
            DISQTY-QUANTITY = DISQTY-AVAL_QUAN.
          ENDIF.
          IF disqty-quantity > 0.
            quan_to_dis = quan_to_dis - disqty-quantity.
            MODIFY disqty TRANSPORTING quantity.
            ADD 1 TO lv_line.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDFORM
    When i am taking characteristics LOBM_VFDAT for sort rule in Cu70 then i am not getting batch determination as i required even if i maintained Shelf expiry date in MSC3n.
    Please suggest where i must look into so that my batch determination would be based on date of consignment recieved.. currently if it s taking based on max qty available in MMBE.
    Regards
    Nitin

    I have already assigned sort rule in VCH1 but dont know which Characteristics i must assign for customer consignment stock on FIFO basis. Could you please tell me the characteristics for it which i must consider?
    LOMB_VFDAT i have already tried but its not working for me.
    Edited by: Nitin Agarwal on Oct 30, 2008 8:14 AM

  • How to get the most current file based on date and time stamp using SSIS?

    Hello,
    Let us assume that files get copied in a specific directory. We need to pick up a file and load data. Can you guys let me know how to get the most current file based on date and time stamp using SSIS?
    Thanks
    thx regards dinesh vv

    hi simon
    i excuted this script it is giving error..
       Microsoft SQL Server Integration Services Script Task
       Write scripts using Microsoft Visual C# 2008.
       The ScriptMain is the entry point class of the script.
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    namespace ST_9a6d985a04b249c2addd766b58fee890.csproj
        [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
        public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
            #region VSTA generated code
            enum ScriptResults
                Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
                Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
            #endregion
            The execution engine calls this method when the task executes.
            To access the object model, use the Dts property. Connections, variables, events,
            and logging features are available as members of the Dts property as shown in the following examples.
            To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
            To post a log entry, call Dts.Log("This is my log text", 999, null);
            To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
            To use the connections collection use something like the following:
            ConnectionManager cm = Dts.Connections.Add("OLEDB");
            cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
            Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
            To open Help, press F1.
            public void Main()
                string file = Dts.Variables["User::FolderName"].Value.ToString();
                string[] files = System.IO.Directory.GetFiles(Dts.Variables["User::FolderName"].Value.ToString());
                System.IO.FileInfo finf;
                DateTime currentDate = new DateTime();
                string lastFile = string.Empty;
                foreach (string f in files)
                    finf = new System.IO.FileInfo(f);
                    if (finf.CreationTime >= currentDate)
                        currentDate = finf.CreationTime;
                        lastFile = f;
                Dts.Variables["User::LastFile"].Value = lastFile;
                Dts.TaskResult = (int)ScriptResults.Success;
    thx regards dinesh vv

  • How can I transfer/merge the backup-data of one iphone onto another iphone?

    I have two iphones and want to merge the backup-data from one to the other without destroying any data on the new one. How can I do it and will this data be replaced automatically or merged?
    Thanks for your help!
    Toni

    As long as you use the same account, you can sync the same apps, contacts, music and other media content. Set up at least one contact and event on your new phone, to be able to merge your contacts and calendars. You can't transfer settings of your 3rd party apps, because this data is stored in your backup, and restoring from your backup will erase your new phone's data.
    See also: "About backups" http://support.apple.com/kb/HT1766
    You can also transfer your mail account settings using the option in the info pane in itunes, as well as the option to replace contacts, calendars, bookmarks and notes during the following sync.

  • How to schedule the webi report based on data changes in the report data

    Hello,
    I want  to schedule a webi report based on data change in a column in the report.
    The scenario is something like below:
    1. If a data of a particular column changes from 2 to 3 than I would like to schedule this report and sent it to users mail box.
    I know how to apply alerts or schedule a report or data tracking for capturing changes in the report but I dont know how to schedule the report only for data changes.
    Anybody done this before.
    Thanks
    Gaurav

    Hi,
    May be these links can help you:
    http://devnet.magicsoftware.com/en/library?book=en/iBOLT/&page=SAP_R_3_Master_Data_Distribution_Defining_Change_Pointers.htm
    SEM-BCS: Load from data stream schedule
    Attribute Change Run

  • How to display data from a recordset based on data from another recordset

    How to display data from a recordset based on data from
    another recordset.
    What I would like to do is as follows:
    I have a fantasy hockey league website. For each team I have
    a team page (clubhouse) which is generated using PHP/MySQL. The one
    area I would like to clean up is the displaying of the divisional
    standings on the right side. As of right now, I use a URL variable
    (division = id2) to grab the needed data, which works ok. What I
    want to do is clean up the url abit.
    So far the url is
    clubhouse.php?team=Wings&id=DET&id2=Pacific, in the end all
    I want is clubhouse.php?team=Wings.
    I have a separate table, that has the teams entire
    information (full team name, short team, abbreviation, conference,
    division, etc. so I was thinking if I could somehow do this:
    Recordset Team Info is filtered using URL variable team
    (short team). Based on what team equals, it would then insert this
    variable into the Divisional Standings recordset.
    So example: If I type in clubhouse.php?team=Wings, the Team
    Info recordset would bring up the Pacific division. Then 'Pacific'
    would be inserted into the Divisional Standings recordset to
    display the Pacific Division Standings.
    Basically I want this
    SELECT *
    FROM standings
    WHERE division = <teaminfo.division>
    ORDER BY pts DESC
    Could someone help me, thank you.

    Assuming two tables- teamtable and standings:
    teamtable - which has entire info about the team and has a
    field called
    "div" which has the division name say "pacific" and you want
    to use this
    name to get corresponding details from the other table.
    standings - which has a field called "division" which you
    want to use to
    give the standings
    SELECT * FROM standings AS st, teamtable AS t
    WHERE st.division = t.div
    ORDER BY pts DESC
    Instead of * you could be specific on what fields you want to
    select ..
    something like
    SELECT st.id AS id, st.position AS position, st.teamname AS
    team
    You cannot lose until you give up !!!
    "Leburn98" <[email protected]> wrote in
    message
    news:[email protected]...
    > How to display data from a recordset based on data from
    another recordset.
    >
    > What I would like to do is as follows:
    >
    > I have a fantasy hockey league website. For each team I
    have a team page
    > (clubhouse) which is generated using PHP/MySQL. The one
    area I would like
    > to
    > clean up is the displaying of the divisional standings
    on the right side.
    > As of
    > right now, I use a URL variable (division = id2) to grab
    the needed data,
    > which
    > works ok. What I want to do is clean up the url abit.
    >
    > So far the url is
    clubhouse.php?team=Wings&id=DET&id2=Pacific, in the end
    > all
    > I want is clubhouse.php?team=Wings.
    >
    > I have a separate table, that has the teams entire
    information (full team
    > name, short team, abbreviation, conference, division,
    etc. so I was
    > thinking if
    > I could somehow do this:
    >
    > Recordset Team Info is filtered using URL variable team
    (short team).
    > Based on
    > what team equals, it would then insert this variable
    into the Divisional
    > Standings recordset.
    >
    > So example: If I type in clubhouse.php?team=Wings, the
    Team Info recordset
    > would bring up the Pacific division. Then 'Pacific'
    would be inserted into
    > the
    > Divisional Standings recordset to display the Pacific
    Division Standings.
    >
    > Basically I want this
    >
    > SELECT *
    > FROM standings
    > WHERE division = <teaminfo.division>
    > ORDER BY pts DESC
    >
    > Could someone help me, thank you.
    >

Maybe you are looking for

  • Customer invoice in CRM as Vendor invoice in ECC

    HI It is continuation of my question , can we post Customer invoice in CRM to be replicated as vendor invoice in ECC ? How can we pay the payment  as Account Payable. I request you to answer my question , it is on proiority . Thanks once again if you

  • STO Excise

    Dear Experts, I have mantained all selections in J1ID..still while doing  Goods Issue for STO its giving BED, AED and SED for the excise item is zero Please check excise base for the item is zero ! In excise tab i am getting   ONLY Part 1,  i am not

  • BI MOBILE Application pin

    For SAP BI MOBILE 1. We can force the user to setup the 8 DIGIT PIN. However - is there a way to not allow the user to change the "require application password  - after 5 minute" setting? Currently the user has to setup an application password but he

  • "Sematic Group" in BPC data loading?

    Hi All: Now, I have a Data Manager Package to load data from BW to BPC, during the loading, I wrote a UJD routine to do the calculation of expense from cost center. The issue is the data volume for one individual cost center is huge. So, those record

  • How to run report without report server

    hi my question : how i can run report without using the report server; by simple URL to the report stored in directory and accessing by HTTPserver; and the report is running by the local client runtime. thinks for replay