Equals (=) vs SIMILAR to data type date

First of all, I am aware that the equal (=) operator is a "comparison operator compares two values for equality."  In other words, in a SQL statement, it will not return true unless both sides of the equation are equal.  For example:

SELECT * FROM Store WHERE Quantity = 200;

The LIKE operator "implements a comparison of pattern match" which attempts to match "a string against a string of models value containing wildcard characters.  For example:

SELECT * FROM Employees WHERE Name LIKE 'Chris%';

Here,

I ask about the date on the ORACLE database data, I found the following, when I write the select statement in this way:

SELECT ACCOUNT.ACCOUNT_ID, ACCOUNT.LAST_TRANSACTION_DATE FROM ACCOUNT WHERE ACCOUNT.LAST_TRANSACTION_DATE LIKE '30-JUL-07';

I get all the lines, I'm looking for. but when I use the equal sign = instead:

SELECT ACCOUNT.ACCOUNT_ID, ACCOUNT.LAST_TRANSACTION_DATE FROM ACCOUNT WHERE ACCOUNT.LAST_TRANSACTION_DATE = '30-JUL-07';

I get nothing even if nothing is different except the equal sign. I can't find any explanation for this you?

Hawk333 wrote:

Here,

I ask about the date on the ORACLE database data, I found the following, when I write the select statement in this way:

SELECT ACCOUNT.ACCOUNT_ID, ACCOUNT.LAST_TRANSACTION_DATE FROM ACCOUNT WHERE ACCOUNT.LAST_TRANSACTION_DATE LIKE '30-JUL-07';

I get all the lines, I'm looking for. but when I use the equal sign = instead:

SELECT ACCOUNT.ACCOUNT_ID, ACCOUNT.LAST_TRANSACTION_DATE FROM ACCOUNT WHERE ACCOUNT.LAST_TRANSACTION_DATE = '30-JUL-07';

I get nothing even if nothing is different except the equal sign. I can't find any explanation for this you?

Just to explain your results...

The LIKE operator only works on strings, so, in that your first example, it causes the left hand side (your DATE column) to be implicitly converted to a string.  Now, your NLS_DATE_FORMAT is obviously DD-MON-RR, so it converts the date to a string of this format, which then matches the string that you have provided on the right side and you get lines.  Now, if your dates got to them, the components then this conversion implcit decreases time to give only the part of the date, so that a very similar match for your channel.

The '=' operator is overloaded to work with many different data types, so in this case, Oracle takes the data type of the left as being the type of data to use, which is DATES, and implcitly converts then the side right (your VARCHAR2 string) to a DATE.  This makes the right hand side a DATE with the component data type "time" 00:00:00.  As your transaction date is likely to have components, they are unlikely to be 00:00:00 (in most cases) If you you games for 30 July 2007 00:00:00, if it was be a line with that timestamp.

Tags: Database

Similar Questions

  • Need Date must equal or after the date of beginning membership-error in po_requisitions_interface_all

    Hi all

    We have created an order forecast manuals for a purchase item in workbench CPSA for some qty and out.

    But, we are not able to get his requisition created in source.

    When we check the _Errors PO_Interface table, we found that it is wrong on with the error like -

    Need for a Date must be equal or after the apparent start date .

    Can someone please help me find the cause of this problem. Any help/pointer in this regard will be highly appreciated.

    Thank you

    Avinash

    Hi Abhishek,

    We have found the root cause of the problem.

    The BPA was not all count start date mentioned in its terms. So put us as BPA created and ran the data collection and the execution plan.

    After that, we could see its BPA release created without any errors.

    Thank you

    Avinash

  • Dates in SelectBox and a report querying return does not

    Hi all

    I'm fighting a bit with this one... I can see what is the problem, but the solution has me confused... (and I'm sure it's a simple...)

    APEX 4.2 on XE... The SUMMIT also has a version. Application of test/test ORACLE.COM Workspace VRS 291 page 7 connection.

    I try to query for a report based on the date of registration.

    The date on the table is of type DATE, and when the file is loaded its cargo directly from sysdate (and on the test on the APEX is simply an Insert into values of payments (ID, CREATED_DATE) (1, SYSDATE)

    I then create a selection list where I want to create a list of dates of the table, so the query is:

    Select distinct (to_char(created_date,'DD-MON-YY')) c1, c2 to_char(created_date,'DD-MON-YY') of payments

    It gives me a list of dates in the select list.

    Then I do a query on the report:

    Select

    "CREATED_DATE."

    "ID".

    of #OWNER #. PAYMENTS

    where created_date = to_date(:P7_SELECT_DATE,'DD-MON-YY')

    to get back the date, then pull it out...

    However, there is no so...    Ive tried all the combinations of to_char, to_date, etc...

    My assumption that the to_char on the selection list select bands the value down to the element of date only to the format character and the to_date on the request he turns his back in a date format...

    On my system, I realized that the time element is a factor. If I insert the date in the system as to_date (to_char(sysdate,'DD-MON-YY'),'DD - MON - YY') then everything works... (as likely Ive undress the time element.  (Which would be OK, but I want as well to the time element for any other purpose.)

    Also, if its related or contributing to I don't know, but it seems to select on the old records of the table...  When I restart the session and select an older date, they show up to... which is a little strange...

    When I looked at the content of the table (by unloading a txt file), some records is loaded with a time and others do not... They are all however, loaded with sysdate. Here is an example... (first column is the ID... some are loaded without time. other time.)

    1629, 2014-05 - 30 T 00: 00:00

    1630, 2014-05 - 30 T 00: 00:00

    1631, 2014-05 - 30 T 00: 00:00

    1632, 2014-05 - 30 T 00: 00:00

    1633, 2014-05 - 30 T 00: 00:00

    1634, 2014-05 - 30 T 00: 00:00

    1635, 2014-05 - 30 T 16: 14:17

    1636, 2014-05 - 30 T 16: 14:17

    1637, 2014-05 - 30 T 16: 14:17

    1638, 2014-05 - 30 T 16: 14:17

    Finally, I have one - show all - on the selectlist too. If I show everything, then update the record in the report (form tab) and set the date with the date picker, it seems also then to query OK when I update...

    ID be grateful if someone could help...

    Rgds

    Richard

    Hi Richard,

    Find out what I did with your application.  I changed the WHERE clause to:

    where created_date between to_date(:P7_SELECT_DATE,'DD-MON-YY') and to_date(:P7_SELECT_DATE,'DD-MON-YY') + .99999
    

    If I understand your condition, you select a day from the drop-down and you want to see the entries for that day.  Because you use a DATE data type, you want to check your created_date covers the full day.  You can do this in ajoutant.99999 (5 nine) to date.  It is the maximum resolution of a day without going over for the next day.  That means that you cover from 00:00:00 to 11:59:59 pm

    Does that help?  Or I read too quickly?

    I guess I have to explain that when you make an equal (=), which is the DATE must be exactly equal all the way at the same time.

    The other way to handle this is to truncate the time:

    When trunc (created_date) = to_date (: P7_SELECT_DATE, 'DD-MON-YY')

    Then both sides are identical with a time "anchored" in midnight 00:00:00

    Thank you

    -Jorge

  • Working with date and time of the request for help from acrobat JavaScript...

    This coming from

    Working with date and time in Acrobat JavaScript (part 1 of 3)

    The following code adds five days to the current date, and then prints the new date in the console window.

    Get the date and time

    var rightNow = new Date();

    Get the value of millisecond

    Article date

    var msRightNow = rightNow.getTime ();

    Calculate in milliseconds, of 5 days

    5 days x 24 hours/day x 60 min / h x 60 s / min x 1000 ms/s

    Challenge of var = 5 * 24 * 60 * 60 * 1000;

    Do the calculation of var CFAbsoluteTime = msRightNow + challenge;

    Create a new Date from the calculated value

    var theNewDate = new Date (finalTime);

    In the actual work on a form code, you'll want to place the

    the object of a field value. But since this is test code, we will

    Print the result to the Console window (great for debugging)

    Console.println ("5 days from now is:" + theNewDate.toString ());

    The foregoing is the exact code (cut and paste)

    The error I get here is;

    ReferenceError: theNewDate is not defined

    1:Console:exec

    undefined

    To get the "undefined" question a lot... it seems to me, learn to distinguish the undefined 'of type' undefined 'variable' and undefined 'value '.

    in this case 'theNewDate' seems to be defined as a variable equal to the current date plus 5 days... BUT I am now "educated" enough to 'see' Why am I getting the error...


    Any thoughts... Any who...

    You need to highlight all the text that you want to run.

    You have not set the rightNow variable before you can apply a method to the variable.

    You can just add a new variable as msRightNow name. Why not use rightNow.

    Executes the code that you provided with a new departure of Acrobat, I get the following error messages:

    rightNow.getTime is not a function

    1:Console:exec

    TypeError: rightNow.getTime is not a function

    1:Console:exec

    undefined

    What you are showing probably works because your previous attempts have left behind them a variable "rightNow" and as long as you do not have the object of time date change too much, you will not notice the error.

    Cleaning of your code:

    get the number of milliseconds of the date object.

    rightNow var = (new Date()) .getTime ();

    define 5 days in milliseconds;
    Challenge of var = 5 * 24 * 60 * 60 * 1000;

    Add 5 days to the value of this moment and assign the result to the last time;
    var CFAbsoluteTime = rightNow + challenge;

    convert finalTime value in a date object.
    var theNewDate = new Date (finalTime);

    display the result;
    Console.println ("5 days from now is:" + theNewDate.toString ());

    Have you tried the code that I provided, it is another way to add days to the date object.

  • date in the tank then char far

    Hello
    Oracle 11 g xe

    ' 1) I want the date in 12 Dec 2012 "in SP and side SP I stated setting date
    so I think that it creates no problem of all weather condition is it customer oracle or any other front. ?

    (2) I (variable type date) date, I want to turn to a char, but it should be in iso Formate (I want iso Formate so that it does not create any problem in any condition).

    (3) and then please tel me how to convert (variable of type date) (date to a char in the iso or any good foramte) (so that it should not be a problem and that's why I wanted to tank date in iso format).

    Yours sincerely.

    Published by: 944768 on December 12, 2012 09:04

    944768 wrote:
    and what format should be used?
    convert date char and char to date.

    It depends on what you want your output to be formatted like and how your entry-as-date string has been formatted.

    For example. If I wanted to convert my rope 13 13 January 2012:28 ' in a date, it would be foolish for me to use a mask of the date "yyyy-mm-dd", because who is not in the format of the string that was passed in.

    function to_date (String, format) is saying "this is a string, I want to convert it to a date - and Furthermore, the contents of the string correspond to dates with this specific format."

    Similarly, to_char (date, format) is "here's a date, I want to convert it into a string that has this particular date format.

  • How to use DATE in where clause

    I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
    Select the query that is used to get the list of records
    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
    I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, is
    do not return only documents not expected
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
    Published by: Barro on March 19, 2012 21:13

    Hello

    Barros says:
    I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
    Select the query that is used to get the list of records

    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
    

    Both operands for AS are supposed to be strings. Do not try to use a DATE, such as SYSDATE, with AS.

    I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, is
    do not return only documents not expected

    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
    

    It returns the results I expect.
    If you'd say what results you expected, could someone help you wite a query to get.

    Assuming that 1 second elapses between the time "ITEM4" is inserted and that 2nd query execution, then, running, available_date will be 1 second less than SYSDATE, so it shouldn't be included.
    If you want to find lines that are on the same calendar day as SYSDATE or later, then use

    WHERE    available_date >= TRUNC (SYSDATE)
    
  • Date of field validation

    Hi all

    I have a simple date field which is pattern(DD/MM/YYYY).

    I need to validate the date so that it should be less than or equal to the current date.

    If the user enters a date later than the current date, that it should give a good message and the value of the date field would become zero.

    Pls help.

    Thank you

    Ludovic

    Hi Eric,.

    The date will be in the correct format when the formattedValue is not the same as the rawValue.  The rawValue will always be in the format yyyy-mm-dd, except when the value does not meet the date pattern.  It will also be a string of type not a Date, so you will need to convert it to a Date to do any math on this.  Try something like the following in the validate event.

    If (DateTimeField1.rawValue! == null)
    {
    If (DateTimeField1.formattedValue is DateTimeField1.rawValue)
    {
    xfa.host.messageBox ("Please enter a date in the format DD/MM/YYYY");
    }
    on the other
    {
    var d = util.scand ("yyyy-mm-dd", DateTimeField1.rawValue);
    If (d > Date.now ())
    {
    xfa.host.messageBox ("" Please enter a date or before today "");
    DateTimeField1.rawValue = null;
    }
    }
    }

    Bruce

  • Q10 of blackBerry data compression

    Hello

    can you tell me if the compression of data on the Q10 and Z10 are similar to data compression on the former as the "BOLD" Blackberry smartphones for example?

    Thank you very much

    Thank you very much

  • Problem when creating a report with a date of schduled

    When I tried to create a report with a schedule (any option except now) I get the error 'Date of the first report occur must be after or equal to the current date", unless I have use a date of 01-10-2012 or later in the first report occurs on the field.  Current date is 2012-08-23.

    Let me know if you can recreate it and if or when there is a fix.

    Hi Tim,.

    We have fixed the problem now. Could you please check that you are able to schedule a report now with start date of today?

    Thank you

    The OnPlus team

  • 802 11b data rates.

    Hmmmm, I have question what a quick Internet search has failed.

    We know 802. 11 b data rates are 1 Mbps, 2 Mbps, 5.5 Mbps and 11 Mbps. My question is, how can we get these numbers?

    The 802. 11 b frequency spectrum signal is sent via, is 22 Mhz wide. In other words, the 22 million oscillations per second.

    Lets take 1 MB/s first. It uses barker coding, with 11-bit sent (or chip) equal to the actual data bit 1. As a result, 22 million (oscillations) each result in a forest (a 1 or a 0). Of these 22 million bits, we know that a chip (11 bits) equals the actual data bit 1. As a result, 22 million/11 = 2 million or 2Mbps. If this shouldn't be 1 MB/s? The 2mbps is a unique swing is equivalent to two bits, doubling the 1mbps to 2 Mbps. Im trying to work on how these 802. 11 b rates are calculated. Math below is probably correlated to somehow how rates are calculated?

    22 000 000 (22 Mhz) / 22 = 1 MB/s

    22 000 000 (22 Mhz) / 11 = 2 Mbps

    22 000 000 (22 Mhz) / 4 = 5.5 Mbps

    22 000 000 (22 Mhz) / 2 = 11 Mbps

    Anyone?

    Dazzler

    Watching a trace of Spectrum Analyzer also lets you understand.

    If you look at a 802. 11B trace, you will see that it resembles a hill, a bump.

    Which means that the centre 11 Mhz are at max power. The other 11 Mhz border are not useful signal, but they are still unusable by others.

    22 Mhz is so the connection you "kill" when you will pass, but only the 11 mhz Center contain a useful signal.

    To remedy this, the 802.11 g brings OFDM and there are several substrings and material. This allows the signal look like "bart simpsons hair", which is very steep on the border, you use not all 20 Mhz then.

  • Yesterday's date


    Hello, I'm going to pull data where the date field is equal to yesterday's date.  Here's what I have so far.  All of the suggestions.

    Date = SYSDATE-1

    Maybe you just want to compare the part of date:

    trunc (date) = Trunc (SYSDATE)-1

    or

    Date > = Trunc (sysdate)-1 and the Date<>

    I will prefer the style later because in this way all the indexes on the Date column should be used as well.

  • Beyond the performance data not available to a host through Virtual Center


    Hello

    I have an ESXi host that relates to the ' No Data Available ' under his paw through Virtual Center performance. Fine appears real-time performance data, but the latest data are not appear and give the error as "No Data Available".

    Within the cluster of 4 hosts, alone is to have the point above. Others are appearing fine performance data.

    In another cluster host ESXi too connected to the same vCenter, I see one of the host is to have a similar question.

    I checked:

    • All work Rollup SQL is run successfully the default schedule.
    • Restarted vpxa service connection to the host directly using the vsphere client.

    I followed the KB article http://kb.vmware.com/selfservice/microsites/search.do?language=en_US & cmd = displayKC & externalId = 2007388 . as suggested in the article when I run the Sub SQL query I see there is no data within who. 

    exec sp_spaceused vpx_hist_statx

    namelinesreserveddataindex_sizeunused
    VPX_HIST_STAT1NULL VALUENULL VALUENULL VALUE0 KB0 KB

    The output is similar (no data) if I run these queries:

    exec sp_spaceused vpx_hist_stat2

    exec sp_spaceused vpx_hist_stat3

    exec sp_spaceused vpx_hist_stat4

    Current configuration:

    ESXi 5.1.0 799733

    vCenter Server 5.1.0 Build 1123961

    Please help solve this.

    I actually planned for the downtime of the host and restarted it.

    Although loading performance data now.

    Thank you!

  • Difference between Date of invoice and Date GL accounting Date Oracle AP

    Hello

    I have a question that might help a lot of people too late.
    I tried to run these queries
    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia. INVOICE_DATE <>aida. ACCOUNTING_DATE

    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia.GL_DATE <>aida. ACCOUNTING_DATE

    I see that there are a lot of results for these queries, where the Date of the invoice is not equal to the posting date and of the GL_Date of an invoice does not match the posting date in the distribution table.
    So, what is the difference between these dates.
    And if I had to take the date of posting of the invoice of the document, the date on which I have to take for these invoices in AP

    Thank you
    Bob

    Hello

    Date of GL:

    The date used to determine the right time of accounting for the transactions of your invoice and payment of GL. You assign a GL Date on your invoice during invoice entry
    and your payments during the creation of payment.

    Date of invoice:

    The invoice date that you assign to an invoice, you enter in Payables. Accounts payable uses this date to calculate the invoice due date, the terms of payment of the invoice. The invoice date may be the date of the invoice, or it can be another date that you specify.

    Posting date:

    The GL Date for distributions of the invoice. If you do not enter a value here or enter a value for GL Date when you submit Payables Open Interface Import, accounts payable will allocate a GL Date based on the GL Date set in the region of the invoice of the Payables Options window.

    Kind regards
    Rahul

  • need to compare two dates in IDM

    I have a requireemnt where I need to compare two fields that are dates. If the first date is greater than the other, then perform a logic 1 other execute logic 2.
    If anyone is implemeneted scenario so please let me know.

    Thank you
    Kalpana.

    Try below I have implemented similar

    Date value = date get of your method
    SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-DD hh: mm :"); ")
              
    try {}
    Date startDate = formatter.parse ("1971-01-08 00:00:01");
    If (value.before (startDate))
    Return BCFConstants.SUCCESS;
    on the other
    No matter what

    In my example, a date has been set. Thus, I have stated here. You can get both the date in the method and put a similar logic

    -nayan

  • Return max date records before the start date

    Hello

    Can anyone help please?

    I have two subqueries, a tableofchildren called, the other called tableofworkers. Tableofchildren identifies the date the child started a class.

    The second query, Tableofworkers, lists the workers and their history of involvement with the child. A child may have had a history with several workers. The worker has an allocatedstartdate indicating when they began to work with the child.

    For my purpose, I need to return the workername and the allocatedstartdate of the worker involved with the child more recently before or at the time when the child began the course.

    I have partially accomplished this with the query below. However, due to the quality of the data, the child may not always have an affected worker (allocatedstartdate) earlier or equal to the start date for the course of the child. In this case, the query fails and does not return the child record, that it excludes from the dataset.

    Can anyone suggest a way to modify this query, so it acts like a left outer query and returns all the records in the child and null raising where they have no worker allocated beginning before or on the date of start of course?

    Thank you! :)
    select *
     from
    (
    select tc.childid, 
    tc.childname, 
    tc.enteredcourse, 
    tw.workername, 
    tw.allocatedstartdate, 
    row_number() over ( partition by tc.childid, tc.enteredcourse order by tw.allocatedstartdate desc) rn
    from tableofchildren tc, tableofworkers tw
    where tc.childid = tw.childid(+)
    and tc.enteredcourse >= nvl(tw.allocatedstartdate,add_months(sysdate,-10000))
    )
    where rn = 1 
    desired output
    CHILDID CHILDNAME            ENTEREDCOURSEDATE         WORKERNAME           ALLOCATEDSTARTDATE        
    ------- -------------------- ------------------------- -------------------- ------------------------- 
    C1000   Johnny Rotten        01-APR-11                 Mrs Gerbil           19-AUG-10                 
    C1256   Doris Dingle         12-AUG-03                 Mrs Pepsi            12-AUG-03                 
    C3466   Bonny Boy            25-MAR-11                 Mrs Jones            23-FEB-11                 
    C4567   Casper Ghost         21-MAR-09                                                                
    C1245   Doris Dingle         20-NOV-06             
    create the table tableofchildren
    (ChildID varchar (6))
    ChildName varchar (20),
    Date of EnteredCourse,
    Date of LeftCourse);

    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ("C1000", "Johnny Rotten', to_date (' 01/04/2011 ',' dd/mm/rrrr'), to_date (' 23/05/2011 ',' dd/mm/rrrr'));
    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ('C1256', 'Doris Dingle', to_date (' 12/08/2003 ',' dd/mm/rrrr'), to_date (' 16/09/2005 ',' dd/mm/rrrr'));
    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ('C3466","Bonny Boy', to_date (' 25/03/2011 ',' dd/mm/rrrr'), to_date (' 28/03/2011 ',' dd/mm/rrrr'));
    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ('C4567', 'Ghost Casper', to_date (' 21/03/2009 ',' dd/mm/rrrr'), to_date('22/04/2010','dd/mm/rrrr'));
    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ('C1245', 'Doris Dingle', to_date (' 20/11/2006 ',' dd/mm/rrrr'), to_date (' 30/12/2008 ',' dd/mm/rrrr'));


    create the table tableofworkers
    (WorkerID, varchar (6))
    WorkerName varchar (20),
    Date of AllocatedStartDate,
    Date of AllocatedEndDate,
    ChildID varchar (6));

    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3453', 'Ms. Whatever", to_date('12/05/2009','dd/mm/rrrr'), to_date ('2009-06-13', ' dd/mm/rrrr'),"C1000");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3442', 'Mr. Toad', to_date('14/07/2010','dd/mm/rrrr'), to_date (' 18/08/2010 ',' dd/mm/rrrr'), "C1000");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W14592', "Mrs gerbil', to_date (' 08/19/2010 ',' dd/mm/rrrr'), NULL,"C1000");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3442', 'Ms. Pepsi", to_date('12/08/2003','dd/mm/rrrr'), to_date (' 22/04/2007 ',' dd/mm/rrrr'),"C1256");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3490', 'Mr. tomato' to_date('12/03/2008','dd/mm/rrrr'), to_date (' 04/30/2009 ',' dd/mm/rrrr'), "C3466");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3453', 'Ms. Whatever", to_date('01/06/2009','dd/mm/rrrr'), to_date ('2010-04-30', ' mm/dd/rrrr'),"C3466");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3457', "Mrs Jones", to_date('23/02/2011','dd/mm/rrrr'), null, "C3466");
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W3453', 'Ms. Jobsworth", to_date('22/11/2006','dd/mm/rrrr'), null, 'C1245');


    create the table OutputWanted
    (ChildID varchar (6))
    ChildName varchar (20),
    Date of EnteredCourseDate,
    WorkerName varchar (20),
    Date of AllocatedStartDate);

    insert into OutputWanted (ChildID ChildName, EnteredCourseDate, WorkerName, AllocatedStartDate) values ("C1000", "Johnny Rotten', to_date (' 01/04/2011 ',' dd/mm/rrrr'),"Mrs gerbil", to_date('19/08/2010','dd/mm/rrrr'));
    insert into OutputWanted (ChildID ChildName, EnteredCourseDate, WorkerName, AllocatedStartDate) values ('C1256', 'Doris Dingle', to_date (' 12/08/2003 ',' dd/mm/rrrr'), "Ms. Pepsi", to_date('12/08/2003','dd/mm/rrrr'));
    insert into OutputWanted (ChildID ChildName, EnteredCourseDate, WorkerName, AllocatedStartDate) values ('C3466","Bonny Boy', to_date (' 25/03/2011 ',' dd/mm/rrrr'), "Mrs. Jones", to_date('23/02/2011','dd/mm/rrrr'));
    insert into OutputWanted (ChildID ChildName, EnteredCourseDate, WorkerName, AllocatedStartDate) values ('C4567', 'Casper the ghost', to_date (' 21/03/2009 ',' dd/mm/rrrr'), null, null);
    insert into OutputWanted (ChildID ChildName, EnteredCourseDate, WorkerName, AllocatedStartDate) values ('C1245', 'Doris Dingle', to_date (' 20/11/2006 ',' dd/mm/rrrr'), null, null);

    Published by: little Penguin November 21, 2011 07:03

    What something like that?

    SELECT childid
         , childname
         , enteredcourse
         , workername
         , allocatedstartdate
    FROM
    (
         SELECT toc.childid
              , toc.childname
              , toc.enteredcourse
              , tow.workername
              , tow.allocatedstartdate
              , ROW_NUMBER() OVER (PARTITION BY toc.childid ORDER BY tow.allocatedstartdate DESC) AS rn
         FROM   tableofchildren   toc
         LEFT JOIN tableofworkers tow ON tow.childid = toc.childid
                         AND toc.enteredcourse >= tow.allocatedstartdate
    )
    WHERE rn = 1
    

    Just note that you need a different RANK and DENSE_RANK analytical ranking function if there is a chance that many workers could be attributed to the children on the same allocatedstartdate.

Maybe you are looking for

  • Some suggestions for the next Qosmios

    The Qosmios are excellent machines for multimedia. However, screens in previous models have low resolution and I believe that one can predict the minimum requirements of the high-def. I hope Toshiba made a better screen to take full advantage of the

  • Cannot connect iPad pro pencil

    I was wondering if it is possible to reconnect a pencil for iPad pro, I clicked accidentally forget this device. Now, while trying to re pair the pencil, I get a warning saying this device can not connect or work properly with the iPad. Advice please

  • Decommissioning of Windows 8 for Windows 7 on a HP Pavilion g7-2272ed: motion graphics driver

    Hi I just installed Windows 7 Professional 64 bit on an HP Pavilion g7-2272ed and I got everything works except the graphics (I think). My question is this. It still says "Standard VGA Graphics Adapter" in my device manager and the graphics are very

  • PRESARIO CQ58-100SL: FAULTY BIOS, IS POSSIBLE TO DOWNGRADE IT SAFELY?

    Nicely,I'll report my problem and I performed the steps in debugging. Intro: Win10 already installed and updated with all devices properly installed and works perfectly, I decided to update the BIOS to the original and very old F.02 to a last F.29 (A

  • HP ENVY 4500: Print status but not printing

    Hello My printer worked properly, and all of a sudden, he cornered me. Whenever I ask an impression, I got the status of good message "printing" but nothing happens. I was cancellation of the printer and my computer, and then start printing again arr