varchar to date

Hello

I would like to convert varchar value stored in a table in order to view a converted date...

as below

the value in the column has values such as "January 2013', ' March 2014'... etc.

I want to display in the form of "Jan 2013', ' March 2014'... i.e. the short form..."

I tried to use the to_date and to_char... but not of much use...

can someone please help...

Thanks in advance...

RK

SQL >-generating sample data:

SQL > with t as (select 'January 2013 "str of union double

2 Select "March 2014' double '.

3            )

4  --

5 - the actual query:

6  --

7. Select str

8, to_char (to_date (str, ' month yyyy ',' nls_date_language = american'), "My yyyy")

9 t

10.

TO_CHAR (TO_DATE (S STR

------------ -----------------

January 2013 Jan 2013

March 2014 2014 Mar

2 selected lines.

Tags: Database

Similar Questions

  • How to convert varchar to date datatype all insert or update in the table

    Hai All

    I need to convert to varchar type to date.

    I have two Tables T1, T2

    Structure of T1

    Code varchar

    Time varchar

    Date varchar

    Structure of T2

    Var EmpName

    Empcode var

    Date of the respondent

    Outtime date

    Intrinsically date

    Date of Introut

    Att_date

    Now I need to spend the time form T1 to T2 respondent, outtime, intrinsically, introut under certain conditions

    So now I need to convert Varchar to Date so that the insert or update

    I tried something

    Insert into T1 (code, respondent, att_date) values

    (To_date(Date|| dele de code temps, «hh24mi de mon-dd-yyyy»), att_date);

    OR update while

    Setting a day set Outtime T2 = To_date(Date||) Time, 'hh24mi mon-dd-yyyy') where...


    I got an error Ora-01861


    Concerning

    Srikkanth.M

    You did not show an example of your date or time values, control may be necessary to add a space between them, like

    To_date(Date || ' ' || time,'dd-mon-yyyy hh24mi')
    
  • Convert Varchar to Date of the

    Hello


    Im trying to convert varchar to date.

    So I used To_date (cilumn, 'DD-MM-YYYY'), since I have to order the set in descending order, I used the same function of conversion with order by clause.


    The problem is... put it is not ordered.


    < sql >

    Select date_created
    Of
    (
    Select distinct
    to_date(created_date,'DD-mm-YYYY') as date_created
    of schedule_backup
    )
    order by desc date_created
    /

    < sql >




    out put is
    =================




    DATE_CREA
    ---------
    26 NOVEMBER 09
    23 NOVEMBER 09
    19 NOVEMBER 09
    16 NOVEMBER 09
    11 NOVEMBER 09
    4 NOVEMBER 09
    30 OCTOBER 09
    11-SEP-09
    4 MARCH 10
    MARCH 1, 10
    FEBRUARY 25, 10

    DATE_CREA
    ---------
    FEBRUARY 22, 10
    17 FEBRUARY 10
    FEBRUARY 15, 10
    11 FEBRUARY 10
    FEBRUARY 9, 10
    FEBRUARY 3, 10
    27 JANUARY 10
    20 JANUARY 10
    JANUARY 15, 10
    JANUARY 4, 10




    Thank you
    REDA

    So it's a problem with the data itself

    Check below

    SQL>SELECT TO_CHAR(a,'DD-MON-YYYY')
      2        ,TO_CHAR(b,'DD-MON-YYYY')
      3    FROM (
      4          SELECT TO_DATE('03-FEB-10','DD-MON-YYYY')    a
      5                ,TO_DATE('03-FEB-2010','DD-MON-YYYY')  b
      6            FROM DUAL
      7         ); 
    
    TO_CHAR(A,' TO_CHAR(B,'
    ----------- -----------
    03-FEB-0010 03-FEB-2010
    
    Elapsed: 00:00:00.04
    SQL>
    

    Data are not in a consistent format DD-MON-YYYY or DD-MON-AA. It is a format of mix that impact of output as shown above

    Concerning
    Arun

  • help with quierying, a table with varchar as dates

    the guys need a little help im close, but I can't just close the deal.
    I have a table that the field is dataytped as varchar2, but she holds a date as such date of today '20100615'.
    I know that the first thing that you guys are going to say is that this must be formatted as a date but it is not my table and I do deal with this.
    Here's how the problem im trying to query for a range of dates, and im having a hell of a time to do.
    as you cannot say my query below im trying to bring back only 15 days worth of data by date.
    can someone please point out what is obvious. I was home for a day now to try to get this working.



    SELECT DISTINCT to_date (fwvitals_date, 'YYYYMMDD') "fwvitals_date".
    OF fwvitals
    where fwvitals_date
    between (((SELECT MAX (fwvitals_date) OF FWVITALS)))
    Double ((SÉLECTIONNEZ to_CHAR (sysdate-15, «AAAAMMJJ»)))

    Hello

    user633029 wrote:
    the guys need a little help im close, but I can't just close the deal.
    I have a table that the field is dataytped as varchar2, but she holds a date as such date of today '20100615'.
    I know that the first thing that you guys are going to say is that this must be formatted as a date but it is not my table and I do deal with this.

    You are absolutely right!

    Here's how the problem im trying to query for a range of dates, and im having a hell of a time to do.
    as you cannot say my query below im trying to bring back only 15 days worth of data by date.
    can someone please point out what is obvious. I was home for a day now to try to get this working.

    SELECT DISTINCT to_date (fwvitals_date, 'YYYYMMDD') "fwvitals_date".
    OF fwvitals
    where fwvitals_date
    between (((SELECT MAX (fwvitals_date) OF FWVITALS)))
    Double ((SÉLECTIONNEZ to_CHAR (sysdate-15, «AAAAMMJJ»)))

    "WHERE x BETWEEN y AND z" is equivalent to
    "WHERE x > = y AND x.<=>
    If y > z, no line will never be allowed, and if there is the great artist of value in your table, then lines (probably) very little, perhaps only 1 will satisfy the same if condition z > y.

    What exactly are you trying to do?
    It helps if post you a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. If the results are conditional, give some examples, for example, "if I run the query at any time on 15 June, I want to... but if it's June 16, so I want to..." »

    If you want the most recent 15 days, including today (that is, when run on 15 June, you want from 1 June until 15 June) then:

    SELECT DISTINCT
         fwvitals_date
    FROM      fwvitals
    WHERE       fwvitals_date     BETWEEN     TO_CHAR (SYSDATE - 14, 'YYYYMMDD')
                   AND     TO_CHAR (SYSDATE,      'YYYYMMDD')
    ;
    

    Fortunately, the strings are in a format such as sorting is explicit, so you don't have to run TO_DATE on each of them and get conversion errors.

    Published by: Frank Kulash, June 15, 2010 21:52

  • Import SQL Developer data change column entire varchar data type

    Hi all

    May I ask, how do to change all the data type of columns using a single click? I want to import a csv file that has more columns then 200. When I use SQL Developer to impoprt it to the Oracle database, there is the possibility to change the data type of the columns, but it is posibble only on a column-by-column. How can I do this with just a click of mouse? In the csv file, there are only numbers, not alphabetic or other characters. But SQL Developer sets automaticully VarChar for all columns when importing the csv file. And if the data type of the columns is of type varChar, the data mining model produced only 10% of predictive confidence. If the columns integer (number), the trust is more than 80%. I use about 50 tables, and each table has more than 200 columns, so changing the data type of columns by a something inhuman is ::(((
    I saved the csv as xlsx file, but when I tried to import it with SQL Developer, I chose this xlsx and Developer SQL closed the import window. If I can't import xlsx...

    Can someone help me?

    Thank you!!!

    You can send the generated here script? I just want to see the DDL Create of the Table and some examples of INSERT statements.

    To remove the rows in the Table, you can run this in the worksheet:

    DELETE

    ;
    COMMIT;

    You can run the Create Table DDL (skip all INSERT queries) to create the table. Then, use the Import Wizard to import data in this table (column all should have correct data types). In the Import Wizard, you can specify the Table to import the data.

  • Query a date in a varchar field

    I'm doing a simple query...

    Count the number of records in a given month.

    I use variables in the URL and use this query (MSSQL)


    SELECT recorddate FROM sometable
    WHERE Year (recorddate) AS ' #Url.year # '.
    AND Month (recorddate) AS ' #Url.month # '.

    It should work in theory, I think, but the problem is that the date field is of type varchar (although all records have a time stamp that has been added as:)

    < INPUT type = "hidden" name = "recordate" value = "#Now () #" >

    I'm not advanced in ColdFusion, so I hope someone can help me... Is there a simple way to do this?

    Thank you!

    I agree with Dan Bracuk you need to store your date values in a date column.  It would be for SQL server DATETIME, SMALLDATETIME, or DATE depending on your version of the server and the requirements.

    As a quick fix, you can use a derived table that converts your varchar in date column values.  Note that this must be used as a work around until you can update your table to use a date column.  This request will probably not run well on large data sets.  You must also use the CFQUERYPARAM tag to avoid SQL injection vulnerabilities.

    
    
        SELECT recorddate
         FROM
         (
             SELECT CONVERT(DATETIME, recorddate) AS recorddate
             FROM sometable
         ) AS Q
         WHERE Year(recorddate) = 
             AND Month(recorddate) =    
    
    
    
  • How to convert varchar to DateTime?

    Hi all

    I have a field - "final payment".

    Data - type Varchar.

    Last completion date must be in the date format. So I want to convert Varchar to Date.

    How can I convert? Can someone please help me solve this problem.

    Hi Nicolas,.

    Gayathri Venugopal wrote:

    I have a table - order and I have a field " Latest_Completion_Date " which is in the format Varchar - ' 20150804'.

    select Latest_Completion_Date from order 
    output- 20150804
    

    I want to convert Latest_Completion_Date - '20150804' in Date format - 15-SEP-07 ".

    How to convert it?

    The column ORDER. LATEST_COMPLETION_DATE with the VARCHAR2 data type?

    How are "Last date" element filling in the form?

    You can use to_date and to_char in combination to get the required format:

    select to_char(to_date(latest_completion_date,'YYYYMMDD'),'DD-MON-RR') latest_completion_date
      from order
    

    Kind regards

    Kiran

  • Data display

    Hello

    I have a table of Bank Transaction table. I want to display the data account no. rates wise sages Date and withdrawals and the closing balance.

    CREATE TABLE bank_transaction

    (acc_no VARCHAR2 (20 BYTE),

    trn_dt DATE,

    trn_type CHAR (1 BYTE),

    sale NUMBER (10.2)

    );

    I want to display data like that.

    Account no.: 100

    Trn_dt flow Withdrawl closed ball

    01-apr-2014 5000 5000

    02-Apr-2014 1000-4000

    03 Apr-2014 2000-7000

    Account no.: 101

    Trn_dt flow Withdrawl closed ball

    01-apr-2014 10000 10000

    02-Apr-2014 1000-9000

    03 Apr-2014 2000-11000.

    I tried like this.

    DECLARE

    CURSOR c1 IS

    SELECT DISTINCT trn_dt FROM b_trn_t ORDER BY acc_no, acc_no, trn_dt;

    CURSOR c2 (VARCHAR, p_trn_dt DATE p_acc_no) IS SELECT acc_no, TRUNC (trn_dt) trn_dt, trn_type, balance OF the b_trn_t

    WHERE acc_no = p_acc_no AND trn_dt = p_trn_dt ORDER BY acc_no, trn_dt;

    v_cr_amt NUMBER: = 0;

    v_db_amt NUMBER: = 0;

    v_clos_bal NUMBER: = 0;

    v_acc_no varchar (12);

    v_trn_dt DATE;

    BEGIN

    I'm IN c1 LOOP

    IF v_acc_no IS NULL THEN

    Dbms_output.put_line (i.acc_no);

    v_acc_no: = i.acc_no;

    ELSIF v_acc_no <>i.acc_no THEN

    v_acc_no: = i.acc_no;

    v_cr_amt: = 0;

    v_db_amt: = 0;

    v_clos_bal: = 0;

    Dbms_output.put_line (i.acc_no);

    END IF;

    FOR j IN c2 (i.acc_no, i.trn_dt) LOOP

    IF j.trn_type = 'C' THEN

    v_cr_amt: = v_cr_amt + j.balance;

    ON THE OTHER

    v_db_amt: = j.balance - v_db_amt;

    END IF;

    END LOOP;

    v_clos_bal: = v_cr_amt-v_db_amt;

    Dbms_output.put_line(i.trn_dt ||) ' D ' || v_cr_amt | ' C ' || v_db_amt | "CLOS BALL | v_clos_bal);

    END LOOP;

    END;

    Hello

    This request obtains all of the information you want:

    SELECT acc_no

    TRUNC (trn_dt) AS trn_dt

    , SUM (CASE WHEN trn_type = ' THEN trn_amt END) filing form

    SUM (CASE WHEN trn_type = 'W' THEN trn_amt END) AS witthdrawal

    SUM (SUM (CASE

    WHEN trn_type = ' THEN trn_amt

    WHEN trn_type = 'W' THEN - trn_amt

    END

    )

    ) OVER (PARTITION BY acc_no

    ORDER BY TRUNC (trn_dt)

    ) AS closing_bal

    OF bank_transaction

    GROUP BY acc_no, TRUNC (trn_dt)

    ORDER BY acc_no, TRUNC (trn_dt)

    ;

    The format is not quite what you asked:

    ACC_NO TRN_DT DEPOSIT WITTHDRAWAL CLOSING_BAL

    -------------------- ----------- ------- ----------- -----------

    100 17 March 2015 6000 6000

    100 24 March 2015 5000 1000

    100 March 25, 2015 10000 5000-6000

    101 17 March 2015 10000 10000

    101 24 March 2015 5000 5000

    101 25 March 2015 5000 1500 8500

    If you are using PL/SQL, to get the results in the exact format you need should be easy.

    Using only SQL, you can get the acc_no on a separate line using GROUP BY GROUPING SETS.  You can use CASES and the GROUPING function to show only the acc_no on some lines and all, but acc_no on others.  May also get the acc_no and the trn_dt in the same column.  (You will need to explicitly call TO_CHAR for this).

    GROUP BY GROUPING SETS can also get a header line after the first acc_no.  If the VARCHAR2 headers are part of the result set, you will need to convert to strings, the total NUMBER of columns using TO_CHAR.

    Maybe some of you have done proof of formatting is not important to you.

  • Date range search

    Hello
    Filtering data for a specific date range does not give the desired result. Currently, the column is a column varchar2.

    Then under query should display the records only 2 for the range of data between 01/01/2013, but his displays all records. Please notify.

    Sample data:


    create table Records_test (B_Recorded_Date VARCHAR2 (4000 BYTE))

    insert into Records_test values('12/04/2013');
    insert into Records_test values('7/25/2000');
    insert into Records_test values('10/30/2003');
    insert into Records_test values('9/5/2006');
    insert into Records_test values('12/5/1994');
    insert into Records_test values('12/19/2013');
    insert into Records_test values('9/4/1992');
    insert into Records_test values('8/7/2007');
    insert into Records_test values('9/28/2005');
    insert into Records_test values('12/10/2004');
    insert into Records_test values('11/28/2011');

    Select * from Records_test
    where
    (
    TO_CHAR (TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY'), ' MM/DD/YYYY') > = to_char (to_date('07/01/2013','MM/DD/YYYY'), ' MM/DD/YYYY')
    and to_char (TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY'), ' MM/DD/YYYY') < to_char (to_date('12/31/2013','MM/DD/YYYY'), ' MM/DD/YYYY')
    )

    04/12/2013
    25/07/2000
    30/10/2003
    05/09/2006
    05/12/1994
    19/12/2013
    04/09/1992
    08/07/2007
    28/09/2005
    10/12/2004
    28/11/2011

    Thank you.

    Hello user7988

    Try this:

    SELECT *.

    OF Records_test

    WHERE

    TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY') > = TO_DATE('07/01/2013','MM/DD/YYYY')

    AND TO_date (substr (B_Recorded_Date, 0, 10), ' MM/DD/YYYY')<>

    ;

    The best way if you set this column as DATE, then there is no need to convert your varchar value date.

    Kind regards
    David

  • Worker name/back and after a return both before course start date?

    Hi all

    Could someone help me with the below please?

    I have a query that back the worker assigned to a child just before where equal to the date the child begins his training course (see below). It works very well.
    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 >= tw.allocatedstartdate(+)
    )
    where rn = 1 
    However, I disocvered that not all children have a worker who they are assigned before / the day they began their courses (mainly because of the poor quality of the data, but a few good reasons why). Therefore, I need to write a report to audit history of children and worker participation including the following columns:

    The worker at a time that the child started the course (CurrDate/CurrWorker),
    The worker who began working with the child more recently to the child from any watercourse (PAWDate/PAWorker).
    The worker who began working with the child more recently after the child from any watercourse (POWDate/POWorker).
    The worker who works with the child before their course (LastDate/LastWorker)
    And how long the worker who works with the child before the end of their course was working with the child (LastWorkerLen)
    These would just return null when it is not subject to conditions.

    I'm not sure what the best approach is to do this.

    I thought I could use Min/Max, which I think should work correctly for columns to date... but it won't work for the text (workername) columns. This is because it will match the name of the worker according to the min/max value of the string, as a min/max value, will sometimes differ from the min/max value of the back and is not directly linked to the beginning dates dates/end through a relational code.

    Can anyone recommend a better/more sustainable approach to the code below?

    Thanks a lot for reading. Maketables below - output 1 is the desired result. :)
    select tc.childid, 
    tc.childname, 
    tc.enteredcourse, 
    
    min(case when tw.allocatedstartdate<=tc.enteredcourse and tw.allocatedenddate>=tc.enteredcourse then tw.allocatedstartdate end) CurrDate, 
    min(case when tw.allocatedstartdate<=tc.enteredcourse and tw.allocatedenddate>=tc.enteredcourse then tw.workername end) CurrWorker,
    max(case when tw.allocatedstartdate<=tc.enteredcourse then tw.allocatedstartdate end) PAWDate, 
    max(case when tw.allocatedstartdate<=tc.enteredcourse then tw.workername end) PAWorker,
    min(case when tw.allocatedstartdate>=tc.enteredcourse then tw.allocatedstartdate end) POWDate, 
    min(case when tw.allocatedstartdate>=tc.enteredcourse then tw.workername end) POWorker,
    max(case when tw.allocatedstartdate>=tc.enteredcourse and tw.allocatedenddate>=tc.leftcourse then tw.allocatedstartdate end) LastDate, 
    max(case when tw.allocatedstartdate>=tc.enteredcourse and tw.allocatedenddate>=tc.leftcourse then tw.workername end) LastWorker
    
    
    from tableofchildren tc, tableofworkers tw
    where tc.childid = tw.childid(+)
    group by
    tc.childid, 
    tc.childname, 
    tc.enteredcourse
    -----------------------------------------------------------

    create the table tableofchildren
    (ChildID varchar (6))
    ChildName varchar (20),
    Date of EnteredCourse,
    Date of LeftCourse);

    insert into tableofchildren (ChildName, EnteredCourse, ChildID, LeftCourse) values ('C1245', 'Doris Dingle', to_date ('2009-03-23', ' dd/mm/rrrr'), to_date (' 09/24/2010 ',' 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 ('W4587', 'Ms. Penguin', to_date('20/02/2009','dd/mm/rrrr'), to_date (' 02/28/2009 ',' dd/mm/rrrr'), 'C1245');
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W4587', 'Ms. Octopus', to_date('01/03/2009','dd/mm/rrrr'), to_date (' 21/03/2009 ',' dd/mm/rrrr'), 'C1245');
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W5982', 'Sir trout', to_date('22/03/2009','dd/mm/rrrr'), to_date (' 25/05/2009 ',' dd/mm/rrrr'), 'C1245');
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W4587', 'Mrs. crab', to_date('26/05/2009','dd/mm/rrrr'), to_date (' 25/09/2010 ',' dd/mm/rrrr'), 'C1245');
    insert into tableofworkers (WorkerID, WorkerName, AllocatedStartDate, AllocatedEndDate, ChildID) values ('W5982', 'Mr. Fishead", to_date('22/11/2010','dd/mm/rrrr'), null, 'C1245');



    create table Output1
    (ChildID varchar (6))
    ChildName varchar (20),
    Date of EnteredCourseDate,
    Date of CurrWorkerDate,
    CurrWorker varchar (20),
    Date of PAWDate,
    PAWorker varchar (20),
    Date of POWDate,
    POWorker varchar (20),
    LastDate date,
    LastWorker varchar (20),
    Number of LastWorkerLen);

    Connect the output 1 (ChildID ChildName, EnteredCourseDate, CurrWorkerDate, CurrWorker, PAWDate, PAWorker, POWDate, POWorker, LastDate, LastWorker, LastWorkerLen)
    values ('C1245', 'Doris Dingle' to_date('23/03/2009','dd/mm/rrrr'), to_date ('2009-03-22', ' dd/mm/rrrr'), 'Mr. trout', to_date('01/03/2009','dd/mm/rrrr'), 'Ms. Octopus', to_date('26/05/2009','dd/mm/rrrr'), 'Mrs. crab', to_date('26/05/2009','dd/mm/rrrr'), 'Mrs. crab", 15)

    Hello

    Looks like you already know how to get information about paw and pow separately.
    The curr and information on the latter is actually more simple: just look for work that has been active on the date of enteredcourse or leftcourse.
    Collect all 4 items is the trickiest part. Do an outer join of tableofchildren with each of the 4 separate result sets. Conditions corresponding to your 'rn = 1"must be part of the join condition, as information may be absent for a child.

    WITH     curr     AS
    (
         SELECT     c_curr.childid
         ,     w_curr.allocatedstartdate     AS currworkerdate
         ,     w_curr.workername          AS currworker
         FROM     tableofchildren          c_curr
         JOIN     tableofworkers          w_curr     ON   c_curr.childid          = w_curr.childid
                                  AND  c_curr.enteredcourse       BETWEEN     w_curr.allocatedstartdate
                                                           AND     w_curr.allocatedenddate
    )
    ,     paw     AS
    (
         SELECT  c_paw.childid
         ,     w_paw.allocatedstartdate                    AS pawdate
         ,     w_paw.workername                         AS pawworker
         ,     ROW_NUMBER () OVER ( PARTITION BY  c_paw.childid
                                   ORDER BY          w_paw.allocatedstartdate     DESC
                                 )                         AS paw_rn
         FROM     tableofchildren        c_paw
         JOIN     tableofworkers        w_paw     ON   c_paw.childid          = w_paw.childid
                                     AND  c_paw.enteredcourse     > w_paw.allocatedenddate
    )
    ,     pow     AS
    (
         SELECT  c_pow.childid
         ,     w_pow.allocatedstartdate                    AS powdate
         ,     w_pow.workername                         AS powworker
         ,     ROW_NUMBER () OVER ( PARTITION BY  c_pow.childid
                                   ORDER BY          w_pow.allocatedstartdate
                                 )                         AS pow_rn
         FROM     tableofchildren        c_pow
         JOIN     tableofworkers        w_pow     ON   c_pow.childid          = w_pow.childid
                                     AND  c_pow.enteredcourse     < w_pow.allocatedstartdate
    )
    ,     lst     AS
    (
         SELECT  c_lst.childid
         ,     w_lst.allocatedstartdate                    AS lastdate
         ,     w_lst.workername                         AS lastworker
         ,     FLOOR ( MONTHS_BETWEEN ( c_lst.leftcourse
                                     , w_lst.allocatedstartdate
                               )
                    )                                   AS lastworkerlen
         FROM     tableofchildren        c_lst
         JOIN     tableofworkers        w_lst     ON   c_lst.childid     = w_lst.childid
                                     AND  c_lst.leftcourse     BETWEEN w_lst.allocatedstartdate
                                                      AND     w_lst.allocatedenddate
    )
    SELECT       c.childid
    ,       c.childname
    ,       c.enteredcourse     AS enteredcoursedate
    ,       curr.currworkerdate
    ,       curr.currworker
    ,       paw.pawdate
    ,       paw.pawworker
    ,       pow.powdate
    ,       pow.powworker
    ,       lst.lastdate
    ,       lst.lastworker
    ,       lst.lastworkerlen
    FROM       tableofchildren     c
    LEFT OUTER JOIN                curr     ON   curr.childid     = c.childid
    LEFT OUTER JOIN               paw     ON   paw.childid     = c.childid
                                     AND  paw.paw_rn          = 1
    LEFT OUTER JOIN               pow     ON   pow.childid     = c.childid
                                     AND  pow.pow_rn          = 1
    LEFT OUTER JOIN               lst     ON   lst.childid     = c.childid
    ;
    
  • Problem with SQL report to modify data

    Hi all

    I don't know that I'm writing this question in the right page or not. But my question is: I have a column in my table which is of type varchar. Data in this column are as Fallows:

    257414/45y
    194662223445 8877/j7tg
    .....
    I wanted to know, is anyway I can show this data in my report without any / or - fallow:

    25741445y
    1946622234458877j7tg

    Just for your information, this is a sql report.

    Thank you

    I read your question because how do you remove both the ' / ' and '-' characters. If true do as follows:

    Select REPLACE(REPLACE('194662223445-8877/j7tg','/'),'-','') from DUAL
    

    At the end of the statement where ") of the DOUBLE appears, these two single quote characters have no space between them. That means replace NULL for the characters you want to replace.

    You can test the statement leaving from DOUBLE. Once satisfied, change it to 'from MyTable '.

    I don't know what to tell you on the TTITLE. It of what I used and always works to print a title.

  • 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.

  • Variable Date format of presentation

    Hi all try to format a variable presentation from a Narrative perspective, is it possible that this can be done by using javascript or html that I can stick in narrative mode.

    I want something like ' the date used is @{indate} to the end of the month.

    Date format must also be JJ.mm.aaaa... his currenty displayed as yyyy/mm/dd... I don't want to add the columns in my report and hide as there seems to be a performance lag when I do this.

    Any ideas... Java gurus out there.

    I tried @{indate} [dd.mm.yyyy..] but it does not work.

    See you soon

    Jenny

    Published by: user5470064 on August 18, 2011 09:58

    Published by: user5470064 on August 18, 2011 09:59

    Here you go...

    I tried in my machine and its working very well...

    In the answers--> in the criteria TAB, in the column fx use under formula...

    «case when 1 = 1 then EVALUATE ('TO_CHAR(%1,%2)' as a varchar (20), date ' @{pv_date} {1998-07-05} ',' dd.mm.yyyy "") else ' ORE time Dim ".» End of the name of the month.

    pv_date is the variable of presentation and

    For "ore time Sun. "" MNTH name ' use any column of varchar data type ...

    Hope that's helpful...

    Thank you
    Ashish Gupta

  • data differences

    RDBMS: 10.2 standard

    Hello
    I have two tables with the same definition.
    table-a
    Identification number
    name varchar
    created_date date

    table-b
    Identification number
    name varchar
    created_date date

    table b is imported from another schema. Now the two same weakening, but table-b may have some documents that might not exist in a table. I can't tell apart them by id id maybe even. Second thing, is date, date stores only date but not timestamp. In general, is not seems to extract the differences.

    I want to know that it is something inserted by Oracle RDBMS (as if oracle is maintaining some timestamp internally with each insert on the table, etc.) to find the differences in this case?

    Don't leave not but

    Select * from table_b
    minus
    Select * from table_a
    
  • Conversion of date format?

    Hello

    I have a collar (varchar) with values like 2010-02-23 12:42:31 I want to convert varchar to date MM-DD-YYYY format

    You can use TO_DATE and TO_CHAR:

    SQL> SELECT TO_CHAR(TO_DATE('2010-02-23 12:42:31','YYYY-MM-DD HH24:MI:SS'),'MM-DD-YYYY') AS NEW_DT FROM DUAL;
    
    NEW_DT
    ----------
    02-23-2010
    

    However, you should seriously consider converting these VARCHAR columns that store dates in the DATE data types.

Maybe you are looking for