Date is JANUARY to the number

Hello

using the 11 g r2

SELECT sum () MO_SETTINGS. CURR_MO_REV_BUDGET) AS Max_rev FROM MO_SETTINGS WHERE MO_SETTINGS. COMPANY_ID = 1 and to_char ()() TO_char to_date () MO_SETTINGS. ((CURR_MO), 'Mm'), 'mm') > ADD_MONTHS() SYSDATE,-12)

I have this query, I need to get the sum of the last twelve months and put in a Multipeers presentation.

MO_SETTINGS . CURR_MO_REV_BUDGET store the value in the

JANUARY

FEBRUARY

MARCH

APRIL

MAY

The main objective is

SELECT max_rev_temp. max_rev as 'Max', Ytd_curr. YTD 0 'current', as 'Min '.

Of

(SELECT sum () MO_SETTINGS. ) CURR_MO_REV_BUDGET) AS Max_rev

OF MO_SETTINGS

WHERE MO_SETTINGS. COMPANY_ID = 1

TO_DATE and () MO_SETTINGS. CURR_MO, 'MONTH') > ADD_MONTHS() SYSDATE,-12)) max_rev_temp,-need number of comparison for twelve months of the end

(SELECT REVENUE_ANNUAL. ANNUAL_REV_ACT_YTD_PRIOR_MO for about a year

OF REVENUE_ANNUAL

WHERE REVENUE_ANNUAL. PERIOD IN

(SELECT MAX () REVENUE_ANNUAL. ) PERIOD)

OF REVENUE_ANNUAL

WHERE REVENUE_ANNUAL. COMPANY_ID = 1

AND TO_CHAR () REVENUE_ANNUAL. (PERIOD, "mm") = SysDate TO_CHAR (), 'mm') - 1

)

AND REVENUE_ANNUAL. COMPANY_ID = 1) YTD_curr

problem

Select distinct to_char ()to_date, TO_char () MO_SETTINGS. () CURR_MO), 'Mm'), 'mm'),(MO_SETTINGS. CURR_MO_REV_BUDGET) AS MO_SETTINGS Max_rev

where to_char ()to_date, TO_char () MO_SETTINGS. () CURR_MO), 'Mm'), 'mm') > ADD_MONTHS() SYSDATE,-12)

et MO_SETTINGS. COMPANY_ID = 1;

ORA-01840: not long enough for the input date format

01840 00000 - not long enough "for the date format of input value.

* Cause:

* Action:

Thanks for your help

Hello

first of all, let me say that this model of data using a VARCHAR2 to save the month is not an ideal solution. I'd rather be having a date column and store TRUNC(date,'MM') which is the first day of the month.

In your model to understand that month refers to the year, you should also check the exercise I don't know if it is corresponding to the solar year.

Also pay attention to this statement:

TO_DATE (MO_SETTINGS. CURR_MO, 'MONTH')

as you do not specify the year, monthly will default to the current year, not matter if the year is the current year or 2 years ago.

that is to say:

Select TO_DATE ('OCTOBER', 'MONTH') dt from DUAL;

DT

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

OCTOBER 1, 13

but perhaps done October refers to October 2012.

Where the fiscal year is the calendar year so you could do something like this:

SELECT TO_DATE (TRIM (curr_mo): fiscal_yr, 'fmMONTHYYYY') mnth

OF mo_settings;

MNTH

---------

JANUARY 1, 13

FEBRUARY 1, 13

MARCH 1ST, 13

Coming to your question you seems to have 3 columns in the corresponding output to the:

Max: the sum of the CURR_MO_REV_BUDGET column for the last 12 months of the MO_SETTINGS table.

Current: value of ANNUAL_REV_ACT_YTD_PRIOR_MO of revenue_annual REVENUE_ANNUAL of the table associated with the last period of the previous month.

Min: a constant with the value 0

If the fiscal year is equal to the calendar year, you can do something like this:

SELECT (SELECT SUM (ms.curr_mo_rev_budget)

OF mo_settings ms

WHERE ms.company_id = 1

AND TO_DATE (TRIM (ms.curr_mo): ms.fiscal_yr, 'fmMONTHYYYY') > ADD_MONTHS (TRUNC (SYSDATE, 'MM'),-12)

), "Max".

(SELECT MAX (ra.annual_rev_act_ytd_prior_mo) KEEP (DENSE_RANK LAST ORDER BY ra.period)

OF revenue_annual ra

WHERE ra.company_id = 1

AND ra.period< trunc(sysdate,="">

) AS "ongoing".

, 0 AS "Min".

FROM DUAL;

who, with the data you have submitted is back:

Current Max Min

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

4552704 3808980 0

I don't know if it's exactly what you wanted. If this isn't the case, explain in detail your needs.

Just keep in mind this about the choice of your dates of arrival:

To_date (TRIM (ms.curr_mo): ms.fiscal_yr, 'fmMONTHYYYY') > ADD_MONTHS (TRUNC (SYSDATE, 'MM'),-12)

the curr_mo concatenated with fiscal_yr must be greater than current_date - 12 months truncated to the month start

that is to say:

curr_mo = "JANUARY" and fiscal_year 2013 will be a date of January 1, 2013

curr_mo = 'OCTOBER' and fiscal_year 2012 will be a date October 1, 2012
ADD_MONTHS (TRUNC (SYSDATE, 'MM'),-12) will be (to date) July 1, 2012

in order to select every month on this condition > Jul-2012 (August 2012)

Since you have been selected in the table REVENUE_ANNUAL the value of the column ANNUAL_REV_ACT_YTD_PRIOR_MO associated with the last period of the previous month, the following condition will include only periods less favourable than those of the first day of this month. :

AND ra.period< trunc(sysdate,="">

means ra.period<>

When you work with large tables using a column without a function may be important for performance reasons. If you have a clue about the period, the index will be used if you specify a condition as I did. If you use a function, i.e.: TO_CHAR (REVENUE_ANNUAL. PERIOD, 'mm') then the index should not be used if you do not have a function of the index.

Kind regards.

Al

Tags: Database

Similar Questions

  • Column data reading according to the number of lines

    Hi guys,.

    I am currently stuck on the problem of recovering the data from my database (MS Access) according to the number of lines, he has at any time (without having to know how many lines there will be during the programming of this part).

    First, I show how my program works. I'm working on an automated food, order and after the customer has chosen his power, system information such as the name of the food, quantity and price of the food will be written to the MS Access database table. (for example table name "Orderingtable" in MS Access) For my case, 1 order of food will occupy 1 line of the database table. In other words, as part of the same, if he orders 3 different foods, 3 rows will be filled in my database table.

    I would then get the part number of 'Quantity' for each order of the database and summarize the amount finally to count the total number of orders in the table of database at any time. This addition of result will be then shown on the Panel before informing the customer how many orders waiting's just prior to his order. In this case, it can get out if he wants to, if the number of orders is too big for its waiting time.

    However, I do not know how many lines my 'Orderingtable' will be 'Orderingtable' because both accumulate lines and data lines until being command to remove. Therefore, I cannot predict how many lines I program the party totals the number of quantity for each line.

    Is it possible that I can get the part of the 'quantity' without having to know the number of rows in the database so that I can count the total number of pending orders just by adding up the value of the quantity for each line?

    I do not wish to "code" my program by limiting the tables of database for us are going to say, only 50 lines at any time.

    Attached below, this is how my database table "Orderingtable" looks at, which will be used to extract the 'Quantity' column so that it can count the total number of orders and be shown/shown on the front panel of my Labview program.

    I hope that you are able to help me!

    Thank you so much in advance.

    See you soon,.

    MUI

    You can also use the SUM function:

    SELECT SUM (Quantity) OF the order WHERE Queue_No = %d

    And no need of an "Order By" clause, if you add just the quantities.

  • Date and time to the number

    I am trying to create a unique order number by using a combination of DateFormat and TimeFormat. The variable that results is still in date and time and it will not insert into a numeric field in my Access database. I use the following code to generate my data. How do I activate the result in just a number so it will go in a numeric field in the DB?

    < CFSET neworder.orderno ='#DateFormat (Now (), "mmddyy") ##TimeFormat (Now (), 'hms') #' >

    Dan, I couldn't get MAX to work for me but I got one right way to do a select and a very detailed WHERE clause. Thanks for all the help on this one.

  • Is it possible to do it in a table? (Count the number of days from a certain date)

    Hello

    I did yesterday a data base to make my job easier. I could make it even more effective if I could understand this delicate piece of business.

    What I have is in my table has a column called "Date completed". This column contains the date when the project was completed. Then, I would like to have another column in the table called "number of days elapsed since completion. This column would have simply taken the date in column "Date completed" and count the number of days since that day and show them in a numeric value (i.e. 28). This way I could do a select and display everything is over for a number of days where I need complete my report (s).

    Thanks for any help. If you know a way to do that is completely different from what I'm trying to please do not hesitate to propose a solution, I'm a complete newbie to this. I took a basic SQL course at the College a few years ago, but never learned to do anything as advanced as this.

    Thanks again

    Your number of days can be easily calculated as trunc (sysdate) - date you completed column.

    You probably don't want to store the number of days in the table (since his will change daily)-instead it calculate on the fly that you query the data (or if you have 11 g you could watch the virtual to make columns persistent calculation rather than the value in the table).

  • change the number of displayed for one single registration

    Hello

    I have a simple block of data with few objects. Is it possible to do a single element in the block as element data non-base and the view of the folder in the item only to display several lines.
    that is all the other elements in the block of data displays a single record, while that particular point should shows 10 records.

    Is it achievable?

    Or should I have to put that element in a separate data block and choose the "Number of records displayed" data block property only 10?

    Thank you
    Didi.

    983448 wrote:
    Hello

    I have a simple block of data with few objects. Is it possible to do a single element in the block as element data non-base and the view of the folder in the item only to display several lines.
    that is all the other elements in the block of data displays a single record, while that particular point should shows 10 records.

    Yes you can. But I'll double-check your design.

    Hamid

    Mark correct/good to help others to get the right answers. *

  • Count the number of rows returned from each view in USER_VIEWS

    For each USER_VIEWS view, I would return the name, creation date, last modified dateand the number of rows returned by this view.

    Here's what I have so far:
    col object_name format a20
    select 
    object_name, 
    created, 
    last_ddl_time
    from user_objects
    where object_type = 'VIEW'
    Returns:
    OBJECT_NAME          CREATED   LAST_DDL_TIME
    -------------------- --------- -------------
    AISLE_AVG            11-FEB-12 11-FEB-12     
    COURSE_AVG           11-FEB-12 20-FEB-12     
    EXE_12_VIEW          11-FEB-12 21-FEB-12     
    L1_P2                17-FEB-12 17-FEB-12     
    L1_P3                17-FEB-12 17-FEB-12     
    L1_P4                17-FEB-12 17-FEB-12     
    L1_P5A               17-FEB-12 17-FEB-12     
    L1_P5B               17-FEB-12 17-FEB-12     
    LAB3_1A              12-FEB-12 20-FEB-12     
    LAB3_1B              12-FEB-12 20-FEB-12     
    LAB3_2A              12-FEB-12 20-FEB-12     
    LAB3_2B              12-FEB-12 20-FEB-12     
    LAB5_1               19-FEB-12 19-FEB-12     
    LAB5_2               19-FEB-12 19-FEB-12     
    LAB5_3               19-FEB-12 19-FEB-12     
    LAB5_4               19-FEB-12 19-FEB-12     
    LAB5_5               19-FEB-12 19-FEB-12     
    LAB5_TIMES           19-FEB-12 19-FEB-12     
    LAB6_1               19-FEB-12 19-FEB-12     
    LAB7_VIEW            20-FEB-12 20-FEB-12     
    PROGRAMS             11-FEB-12 21-FEB-12     
    STUDENT_GPA          11-FEB-12 21-FEB-12     
    
     22 rows selected 
    How can I add a last column that counts the number of rows returned by this view?

    EDIT - here is a dump of my paintings, and here are my views.

    Edit2 - this is possible by using the DECODE function, by chance?

    The function...

    CREATE OR REPLACE FUNCTION view_row_count (view_name VARCHAR2)
    RETURN NUMBER
    AS
    retval NUMBER;
    BEGIN
    EXECUTE IMMEDIATE
    'select count(*) from '||view_name INTO retval;
    RETURN retval;
    END view_row_count;
    /
    

    And now the query...

    select
    object_name,
    created,
    last_ddl_time,
    view_row_count(object_name) as view_row_count
    from user_objects
    where object_type = 'VIEW'
    
  • SQL to count the number of days of January with a range of dates

    I have data like this, how to calculate the number of days with January in this date range.

    BEGINNINGENDDAYS OF JAN
    12/12/201320/01/201420
    21/01/201402/02/201411

    Hello

    So, you want to count the number of days between

    (a) either start_dt, or January 1, 2014 (prevailing later) and

    (b) or end_dt or January 31, 2014 (whichever comes first).

    However, if start_dt and end_dt are prior to January 2014 (or both are later) which will result in a number negative if you take the difference or 0, if it is higher.

    This looks like a job for the GREATER and LESS than functions.

    SELECT start_dt - START is not a column name good

    , end_dt - is neither END

    BIGGER (1 + LESS (end_dt, DATE ' 2014-01-31'))

    -Most GREAT (start_dt, DATE '' 2014-01-01)

    * v

    ) AS jan_days

    FROM table_x

    ;

    If you would care to post CREATE TABLE and INSERT instructions for some examples of data, then I could test it.

  • The data exported from Yardi, I need a column to change to have one - in front of the number

    I exported my Yardi GL to Excel.  In my debit column, I need to have a + before the number and one - to put in front of my number in the credit column.  I got tired of the number format, but it does not work.  I even chose the entire worksheet and copy then paste values to see if that would help and it has not done.  Any suggestions?

    An alternative is to define not as a date, but define it as a text.

    Here is a workaround to get the YYYYMM format you prefer:

    1. Ensure that your source to convert or A1 is defined as a text. Simply right-click on the cell, click Format cell..., select text in the category, and then click OK.
    2. The destination cell must use this form:
    • = CONCATENATE ("20", RIGHT(A1,2), LEFT(A1,2))

    This way you can convert to 201501. However, please note that the formula which suggested us will convert only year 2000 and beyond. Therefore, if the source cell contains 01/99 (assuming that the January 1999), it will be converted incorrectly to 209901 instead.

    Alternatively, you can use the form below instead:

    • = IF (VALUE (RIGHT(A1,2))< 50,="" concatenate("20", ="" right(a1,2),="" left(a1,2)),="" concatenate("19", ="" right(a1,2),="">

    The formula above converts 50-99 as of the early 1900s and 00-49 as of the early 2000s.

    Let us know if you need more assistance.

    Kind regards

    Kem Lun

  • How to count the number of Sundays between the two dates

    Hello

    I want the number of Sundays between the two dates

    example of

    number of number of Sundays between 4 January 2013 ' and April 30, 2013 "in a select query, I have to include this as a sub query in my select statement.

    nordine B wrote:
    Hi Frank,.
    Have 1 doubt...

    In many countries the week could me "Monday". How the application handles it?
    Or did I get something wrong?

    Help, please!

    For ' IW'(ISO week) early in the day is always Monday...

    It's so simple - calculate the weeks between two dates based on Monday... This is the number of Sundays...

    NEXT_DAY is another option...

    SQL> with dd as
      2  (
      3      select TO_DATE('01-04-2013','dd-mm-yyyy') fdt, TO_DATE('30-04-2013','dd-mm-yyyy') ldt from dual
      4  )
      5  SELECT       fdt,ldt,
      6            (next_day(ldt,'sunday')-next_day(fdt-1,'sunday'))/7 sdays
      7  FROM         dd;
    
    FDT       LDT            SDAYS
    --------- --------- ----------
    01-APR-13 30-APR-13          4
    

    Published by: JAC on May 2, 2013 12:20

  • Difference in the number of records for the same date - 11 GR 2

    Guy - 11 GR on Windows2005 2, 64-bit.

    BILLING_RECORD_KPN_ESP - is a monthly partitioned table.
    BILLING_RECORD_IDX #DATE - is a local index on "charge_date" in the table above.

    SQL > select / * + index (BILLING_RECORD_KPN_ESP BILLING_RECORD_IDX #DATE) * /.
    2 (trunc (CHARGE_DATE)) CHARGE_DATE;
    3 count (1) Record_count
    4. IN "RATOR_CDR". "" BILLING_RECORD_KPN_ESP ".
    where the 5 CHARGE_DATE = January 20, 2013.
    Group 6 by trunc (CHARGE_DATE)
    5 m

    CHARGE_DATE RECORD_COUNT
    ------------------ ------------
    2401 20 January 13-> > some records here.

    -> > Here I can see only '2041' records for Jan/20. But in the query below, it shows "192610" for the same date.

    Why is this difference in the number of records?

    SQL > select / * + index (BILLING_RECORD_KPN_ESP BILLING_RECORD_IDX #DATE) * /.
    (trunc (CHARGE_DATE)) CHARGE_DATE,
    2 count (1) Record_count
    3. FOR "RATOR_CDR." "" BILLING_RECORD_KPN_ESP ".
    "4 where CHARGE_DATE > 20 January 2013."
    Group of 5 by trunc (CHARGE_DATE)
    6 order by trunc (CHARGE_DATE)
    5 m

    CHARGE_DATE RECORD_COUNT
    ------------------ ------------
    192610 20 January 13-> > more records here
    JANUARY 21, 13 463067
    JANUARY 22, 13 520041
    23 JANUARY 13 451212
    JANUARY 24, 13 463273
    JANUARY 25, 13 403276
    JANUARY 26, 13 112077
    27 JANUARY 13 10478
    28 JANUARY 13 39158

    Thank you!

    Because in the second example you also select rows that have a nonzero component.

    The first example selects only rows that are 00:00:00

    (by the way, you should ask questions like this in the forum SQL)

  • How to get the number of days in a month of belonging to a range of dates

    Hi, I'm going crazy around a problem, I have 2 dates and one month I wanto to retrieve the number of days belonging to the months that fall within the range.

    for example:

    month of January 2011. begin_date = January 11, 2011, May 30, 2011 end_date result is 21
    month of January 2011. begin_date = December 11, 2010, result of end_date, January 10, 2011 10
    month January 2011 .begin_date = 2 February 2011, end_date may 25, 2011 result 0
    month of January 2011. begin_date = January 3, 2011, January 5, 2011 result DATE END 3

    and so on...

    I appreciate any suggestion
    Thank you


    Andrea

    Something like that... ?

    SQL> with t as
      2  (select  to_date('11/01/11','dd/mm/yy') from_dt,
      3           to_date('30/05/11','dd/mm/yy') to_dt,
      4           'Jan-11' mnth from dual)
      5  select least(last_day(to_date(mnth,'Mon-yy')),to_dt) -
      6         greatest(to_date(mnth,'Mon-yy'),from_dt) cnt
      7  from t  ;
    
           CNT
    ----------
            20
    

    If 0 is also expected...

    SQL> with t as
      2  (select  to_date('11/01/11','dd/mm/yy') from_dt,
      3           to_date('30/05/11','dd/mm/yy') to_dt,
      4           'Jan-11' mnth from dual union all
      5           select  to_date('11/01/11','dd/mm/yy') from_dt,
      6           to_date('30/05/11','dd/mm/yy') to_dt,
      7           'Jan-12' mnth from dual
      8           )
      9  select from_dt,to_dt,mnth,
     10         greatest(
     11              least(last_day(to_date(mnth,'Mon-yy')),to_dt)
     12              -
     13              greatest(to_date(mnth,'Mon-yy'),from_dt)
     14                 ,0) cnt
     15  from t;
    
    FROM_DT   TO_DT     MNTH          CNT
    --------- --------- ------ ----------
    11-JAN-11 30-MAY-11 Jan-11         20
    11-JAN-11 30-MAY-11 Jan-12          0
    

    Published by: JAC on February 9, 2012 19:22

  • Photos shows a date incorrect (January 1, 1970), even if the date in the Finder is correct

    Recently, when I import pictures I took on my phone Android in Photos, they all indicate the date created January 1, 1970 (which, in my opinion, happens when there is no data to date) even if the described Finder properly the date of creation.

    It also happened when I tried to import into iPhoto. The only exceptions are the videos and photos, that I have edited in my Android phone before copying them on my computer. I'm not sure if the problem lies with Photos or my phone, but apparently from the Finder Gets the correct date information should - not be possible for Photos as well?

    Date Finder, do you mean the creation of file? Pictures which have a date in the form of data in the file? It's different to the creation date of the file that you usually see in the finder. Same place as the manufacturer of location data and camera will be stored.

    Would the image Photo app is not looking at the creation Date of the file, but the Date field for Photo taking

  • writing cannot be porformed, because data channels number does not match the number of channels in the task

    Hello

    I'm writing analogues of the buffer to several channels using NOR-6723.

    For some reason any, whenever I go to the buffer double function (1-d) that contains buffers for all channels.

    I always find myself with exception indicating that the numbers of channels in the data are '1 '.

    I use c#:

    Task m_TaskHandle = new Task();
    
    string sChannelsList = "Dev2/ao21:23";
    
    m_TaskHandle.AOChannels.CreateVoltageChannel(
    
    sChannelsList,
    
    "", 0, 5, AOVoltageUnits.Volts );
    
    int iNumberOfSamples = 4;
    
    double dSamplingFrequency = 1000;
    
    m_TaskHandle.Timing.ConfigureSampleClock("",
    
    dSamplingFrequency,
    
    SampleClockActiveEdge.Rising,
    
    SampleQuantityMode.ContinuousSamples,
    
    iNumberOfSamples /* Only relevant if mode is FiniteSamples */);
    
    // Data code is heredouble[] adSampleBuffer;// array values removed from this code snippet (here i have function that generates data)// array size is: num_of_samples * total_channels (in this case 4 * 3)
    
    AnalogSingleChannelWriter ChanWriter = new AnalogSingleChannelWriter(m_TaskHandle.Stream);
    
    ChanWriter.WriteMultiSample(false, adSampleBuffer);
    
    m_TaskHandle.Start();
    

    Not sure I'm I missing, how the MSTDIO determines the "number of data channels", I receive as an exception, it is always equal to 1.

    would appricate to help.

    Thank you.

    Hi idanbis,

    As the snippet you posted, you can create more than one channel using the ao21:23 range. That said, you should use AnalogMultiChannelWriter to configure your write instead of AnalogSingleChannelWriter operation.

    To write using AnalogMultiChannelWriter::WriteMultiSample (boolean, double, you must know the data you want to write must be stored in a 2D array.) Each element in the first dimension of the array corresponds to a channel in the task, while each item in the second dimension, to a sample of write on its channel. For example, that:

    Double [,] data = new double [numChannels, numSamplesPerChannel];

    Then:

    data [0, 0... numSamplesPerChannel]; It is the set of all samples in the first string (ao21 in your code).

    I hope that was helpful. Let me know if I left any doubt remaining.

    Best regards

    Anzurio

  • Why do write can not be performed because the number of data channels does not match number of channels in the task.

    Possible reasons:

    Scripture cannot be performed because the number of data channels does not match number of channels in the task.

    When writing, provide data for all channels in the task. You can also change the task so that it contains the same number of channels as the written data.

    Number of job channels: 8
    Number of data channels: 1

    Lama says:

    The DAQmx vi writing gives me the error. If I run a single channel, isn't a problem. Multichannel gives me error.

    You are funny! Why tie yourself to work VI (single channel) instead of one that gives you errors (multichannel)?

    (If your car does not work, you bring car your wives to the mechanic, right!)

    What is the exact text in the multichannel 'physical channels' when you do the AO control?

    Lama says:

    I did a sequence to ensure that each function has been run in the correct order. Wouldn't a race condition.

    All you have to do is wire the 'start of task' error at the entrance of error of the DAQ assistant and then back to 'stop task' and things will run in order. Guaranteed! Think the stream! Everything else can run in parallel or the order is irrelevant.

    First convert the sequence stacked to a sequence of plate, remove the flat sequence and add the mentioned son. Now, do a "cleaning pattern.

    A when stacked with the inhabitants of the sequence is one of the worst construction you can possibly do. It makes the code difficult to follow, impossible to maintain, difficult to debug.

  • Find the number of days between the dates...

    Hi friends,

    I am new to this development of blackberry applications so I do not know how to find the number of days between two days. Y at - there any API is avilable otherwise we have to write our own code. In fact, I tried GregorianCalendar but I get error that cannot find the symbol but I already imported net.rim.device.api.util and package java.util also... Please give an idea how to solve this problem.

    with respect,

    s.Kumaran.

    Use DateField class instances to represent dates on the screen.

    And your code will be as follows:

    long date1 = date1DateField.getDate ();

    long date2 = date2DateField.getDate ();

Maybe you are looking for