Query to  get  a date column is greater than a year

Hi all,
I had a table :
order date
1 4/4/2010 9:10:09 AM
2 5/6/2011 9:10:09 AM
my select statement should return a row which is more than a year
and date is timestamp(3) datatype (considering leap year to)
can any one help me
Thanks in advance!!!!
Edited by: 846773 on Apr 11, 2011 1:21 PM

Justin Cave wrote:
or
WHERE order_date < sysdate - interval '1' year Careful:
SQL> select date '2012-02-29' - interval '1' year
  2  from dual;
select date '2012-02-29' - interval '1' year
ERROR at line 1:
ORA-01839: date not valid for month specified
SQL> SY.

Similar Messages

  • Query to get the data of all the columns in a table except any one column

    Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
    For Example:
    Let us consider the EMP table.,
    From this table except the column comm all the remaining columns of the table should be listed
    For this we can write a query like this..
    Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
    Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
    As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
    but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
    Is there any other way of writing the query to get the required result..?
    Thanks..

    Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
    If you really need to list all the columns for a table because you don't want to type them, just use something like...
    SQL> ed
    Wrote file afiedt.buf
      1  select trim(',' from sys_connect_by_path(column_name,',')) as columns
      2  from (select column_name, row_number() over (order by column_id) as column_id
      3        from user_tab_cols
      4        where column_name not in ('COMM')
      5        and   table_name = 'EMP'
      6       )
      7  where connect_by_isleaf = 1
      8  connect by column_id = prior column_id + 1
      9* start with column_id = 1
    SQL> /
    COLUMNS
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
    SQL>

  • Export error: value of length column (38) greater than VARDATA column (36)

    Hello @,
    I am performing an export on HP-UX/Oracle of a R/3 Enterprise 1.10 system.
    I already use got the latest R3load binary. For pool table KAPOL I get
    this strange error and I couldn't find any further information about it:
    cat SAPPOOL.log
    (EXP) TABLE: "DEBI"
    (EXP) TABLE: "DVPOOL"
    (EXP) TABLE: "DVPOOLTEXT"
    (EXP) TABLE: "FINPL"
    (EXP) TABLE: "GLTP"
    (EXP) TABLE: "KALK"
    value of length column (38) greater than VARDATA column (36)
    (CNVPOOL) conversion failed for row 356 of table A004       VARKEY = 001V ZSP0003010TI060067A.01      00000000 
    (CNV) ERROR: data conversion failed.  rc = 2
    (DB) INFO: disconnected from DB
    /usr/sap/AVT/SYS/exe/run/R3load: job finished with 1 error(s)
    /usr/sap/AVT/SYS/exe/run/R3load: END OF LOG: 20110117114148
    SQL> desc kapol
    Name                                      Null?    Type
    TABNAME                                   NOT NULL VARCHAR2(30)
    VARKEY                                    NOT NULL VARCHAR2(195)
    DATALN                                    NOT NULL NUMBER(5)
    VARDATA                                            RAW(36)
    SQL> select length(vardata),count(*) from kapol group by length(vardata);
    LENGTH(VARDATA)   COUNT(*)
                 72     183681
    select dataln,count(*) from kapol  group by dataln;
        DATALN   COUNT(*)
        -32730          2
            36     183679
    Does this mean that one row in KAPOL has to be changed from within SAP?
    Or could it be an error/bug within R3load?
    Regards,
    Mark
    Edited by: Mark Foerster on Jan 17, 2011 12:46 PM

    Maybe this information is of any help:
    I opened a support call and was told by SAP support to change the
    two entries from -32730 to -32732. Don't ask me why...

  • Hide/disable a row of a list when "date" column is less than today's date.

    Hi,
    We are using a "Finalsubmitted" date column in my list. my requirement is once that date of Finalsubmitted column is expired(less than today's date), total row should be in hide/disable mode.Could you help me to achieve this.
    Thanks.

    that is a drop down, showing the results from another list based on our selection.
    We have used SP services for that.
    But, date conversion is wrong on  var pubdate= new date(dateselected.value) line.
    It is showing "NaN(Not a number)" . date format it is giving DDMMYYYY.
    But, i need MMDDYYYY. How can we convert in JavaScript.
    Plz check below code.
    <script language="javascript" type="text/javascript">
    $(document).ready(function()
    today = new Date();
    getTagFromIdentifierAndTitle("select","Lookup","Dates").onchange = function() {ChangeEvent1()};
    function ChangeEvent1()
    var dateSelected = document.getElementById("Dropdown ID");
    var pubdate = new Date(dateSelected.value);
    if(pubdate<=today)
    $("input[value$='Save']").attr('disabled', true); //button hides
    alert("Publishing Date should be greater than Today's Date");
    else
    $("input[value$='Save']").attr('disabled', false); //button shown
    function getTagFromIdentifierAndTitle(tagName, identifier, title) {
    var len = identifier.length;
    var tags = document.getElementsByTagName(tagName);
    for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;
    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
    return tags[i];
    return null;
    }</script>

  • PO Doc Date is not Greater than MIGO Date.

    Dear All,
    I ahve Done PO with doc date 02.02.2009 & i create MIGO as 25.01.2009 System is accepting this document.
    so i want restriction of this procedure.
    PO date is not greater than MIGO date.
    Thanks
    Shital

    hi
    for ur problem just set message no ME039 as error message
    go to SPRO>MM>Purchasing>Environment Data>Define Attributes of System Messages
    here make message ME -039 as error
    regards
    KI

  • From date(ETTIFN-AB) greater than To date(ETTIFN-BIS) in table ETTIFN

    Hi,
    In my client system I have observed that in table ETTIFN(Installation Facts (Normal) for a specific operand the "From date" field contains date which is greater than the date contained in the "To date" field.
    eg: from date = 20/7/2008
         To date     = 4/4/2008
    This is observed in multiple records of the same operand.
    Can any one throw some light on this issue.
    1) How this could have happened, and using what transaction.
    2) what will be the effect of such entry on rate category and billing.
    3) how this can be changed.
    any suggestion will be highly appreciated.
    thanks
    ajay

    In my experience, this a sort of a bug that happens in several time sliced tables.
    However, the programs only seem to take the BIS date into account, so this inconsistency doesn't create any problems.
    If I'm not mistaken, there are some notes on this error, but I'm not sure if it'll fix the problem for every table.
    When in doubt, create a customer message to SAP explaining in which cases the error is generated and ask for a correction.

  • Need to create a workflow after Date Modified is greater than 7 days

    I'm using SharePoint Deisnger 2010 and attempting to create a workflow to generate an email after the Date Modified is greater than 7 days. Checking to see if there is a way to create this workflow without creating a "calculated" field with a date.
    Have:
    If Current Item:Modified is greater than Today
    But would like to have 7 days not today or a set date.
    What's the best way to do this?

    Hello,
    In addition to Bistech, here is link to set date in WF context variable.
    http://stackoverflow.com/questions/17082455/sharepoint-designer-2010-set-variable-today-x-days
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to set-up Payment terms greater than 10 years

    We have payment terms that go beyond 10 years.  In the configuration of the payment terms, the "Additional months" field (V_T052-ZMONA) only contains 2 characters.  10 years * 12 months = 120 months which is already 3 characters long.
    Anybody know a way of how to set-up payment terms which is greater than 10 years?  Any user exits?
    Appreciate any help!
    DGE
    Edited by: DGE on Jan 3, 2008 5:43 AM

    Hi Amlan Sarkar,
    I went through IMG: Financial Accounting (New)> Accounts Receivable and Accounts Payable> Business Transactions> Outgoing Invoices/Credit Memos> Maintain Terms of Payment.
    Now for me to configure Payment terms up to year 2018 (for example); i need to enter in field "Additional months" value = 120.  120 is 10 years * 12 months, since receivables for the year 2018 is 120 months from the current date.
    How the "Additional months" field is only 2 characters long.  Therefore I am unable to enter the value 120 which is 3 characters long.
    Any ideas on how I can configure this?
    Thank you.

  • Query for Getting previous date in oracle in specifc scenario

    I have the below data in a table A which i need to insert into table B along with one compute column.
    TABLE A:
    Account_No | Balance | As_on_date
    1001 |-100 | 1-Jan-2013
    1001 |-150 | 2-Jan-2013
    1001 | 200 | 3-Jan-2013
    1001 |-250 | 4-Jan-2013
    1001 |-300 | 5-Jan-2013
    1001 |-310 | 6-Jan-2013
    Table B:
    In table B,there should be no of days to be shown when balance is negative and the date one which it has gone into negative.
    So,for 6-Jan-2013,this table should show below data:
    Account_No | Balance | As_on_date | Days_passed | Start_date
    1001 | -310 | 6-Jan-2013 | 3 | 4-Jan-2013
    Here,no of days should be the days when the balance has gone negative in recent time and not from the old entry.
    I need to write a sql query to get the no of days passed and the start date from when the balance has gone negative.
    I tried to formulate a query using Lag analytical function,but i am not getting how should i check the first instance of negative balance by traversing back using LAG function. Even the first_value function was given a try but not getting how to partition in it based on negative value.
    Any help or direction on this will be really helpful.
    Thanks

    I think you can apply the Tabibitoshan method here. The query is more complex but performs better than other methods. For an explanation, see Tabibitosan method tutorial by Aketi Jyuuzou
    The idea behind the method is to identify "continuous" records without gaps. Here I identify records that are "continuous" because they contain an uninterrupted series of negative balances.
    drop table t;
    CREATE TABLE t (Account_No , Balance , As_on_date) AS SELECT
    1001 ,-100 , to_date('1-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-150 , to_date('2-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 , 200 , to_date('3-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-250 , to_date('4-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-300 , to_date('5-Jan-13', 'DD-MON-YY') FROM dual UNION ALL SELECT
    1001 ,-310 , to_date('6-Jan-13', 'DD-MON-YY') FROM dual;
    SELECT Account_No, Balance, to_char(As_on_date, 'DD-MON-YYYY') as_on_date,
    CASE
      WHEN balance < 0
      THEN row_number() OVER(PARTITION BY account_no, grp ORDER BY as_on_date)
    END days_passed,
    CASE
      WHEN balance < 0
      THEN to_char(
        first_value(as_on_date) OVER(PARTITION BY account_no, grp ORDER BY as_on_date),
        'DD-MON-YYYY'
    end start_date
    from (
      SELECT Account_No, Balance, As_on_date,
      CASE WHEN balance >= 0 THEN NULL ELSE
        row_number() OVER(PARTITION BY account_no ORDER BY as_on_date) -
        sum(CASE WHEN balance < 0 THEN 1 ELSE 0 END) OVER(PARTITION BY account_no ORDER BY as_on_date)
      end grp
      FROM t
    order by account_no, As_on_date;
    ACCOUNT_NO
    BALANCE
    AS_ON_DATE
    DAYS_PASSED
    START_DATE
    1001
    -100
    01-JAN-2013
    1
    01-JAN-2013
    1001
    -150
    02-JAN-2013
    2
    01-JAN-2013
    1001
    200
    03-JAN-2013
    1001
    -250
    04-JAN-2013
    1
    04-JAN-2013
    1001
    -300
    05-JAN-2013
    2
    04-JAN-2013
    1001
    -310
    06-JAN-2013
    3
    04-JAN-2013

  • Need a sql query to get multiple dates in rows

    Hi All,
    i need a query to get dates for last 7 days and each dates should be in one row...
    but select sysdate from dual..gives one row...
    Expexcted Output
    Dates:
    01-oct-2013
    30-sep-2013
    29-sep-2013
    28-sep-2013
    27-sep-2013
    26-sep-2013

    Hi,
    Do you mean that you want all 7 dates together on 1 row?
    Here's one way:
    SELECT LISTAGG ( TO_CHAR ( SYSDATE + 1 - LEVEL
                              , 'DD-Mon-YYYY'
                    ) WITHIN GROUP (ORDER BY LEVEL)    AS txt
    FROM    dual
    CONNECT BY LEVEL <= 7
    This is an example of String Aggregation, that is, taking a column on multiple rows, and concatenating all the values (however many htere happen to be) into 1 big string column 1 row.
    Like everything else, exactly how to do it depends on your Oracle version.
    For more on String Aggregation, including differetn techniques for different versions, see http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    Message was edited by: FrankKulash
    Sorry, I mis-read the question.

  • Query to get the date from to

    hello anyone,
    How can I create a query having 2 date and 2 variable of kind:
    from 1 date 05/06/2004
    to   2 date 15/06/2004
    yes for 2 days
    no for  1 day
    that is,
    i wish get the date with yes for 2 days and not for 1 day, this is, that I want
    05/06/2004 sabato
    06/06/2004 domenica
    08/06/2004 martedì
    09/06/2004 mercoledi
    11/06/2004 venerdi
    12/06/2004 sabato 
    14/06/2004 lunedi
    15/06/2004 martedithanks in advance

    Hi,
    The WHERE clause controls which rows will be displayed.
    If your requirements change, change the WHERE clause to reflect them.
    For example:
    DEFINE     from_date     = "TO_DATE ('05/06/2004', 'DD/MM/YYYY')"
    DEFINE     to_date          = "TO_DATE ('15/06/2004', 'DD/MM/YYYY')"
    DEFINE     yes_cnt          = 3
    DEFINE     no_cnt          = 2
    SELECT  &from_date + LEVEL - 1        AS dt
    FROM     dual
    WHERE     MOD ( LEVEL
             , &yes_cnt + &no_cnt
             )          BETWEEN  1
                       AND      &yes_cnt
    CONNECT BY  LEVEL <= 1 + &to_date
                         - &from_date
    ORDER BY  dt;This will work as long as you want the first &yes_cnt rows to be displayed (assuming there are that many), and the next &no_cnt rows not to be displayed, then another &yes_cnt rows to be displayed and another &no_cnt rows not to be displayed, and so on.
    I assume that &yes_cnt is a postive integer, and that &no_cnt is a non-negative integer. (That is, &no_cnt may be 0.)

  • Sql query to get Thursday (Date) for the year 2014

    Hello All,
    I want to get the date for all the Thursdays in the year 2014. How can I achieve this using SQL query? Can anybody give me a hand with this? Thanks.
    Amol

    Hi,
    Check if this can help you
    DECLARE @counter INT
    DECLARE @Date Date
    SELECT @counter = 0
    Select @Date = '20131226'
    WHILE @counter <= 52
    BEGIN
    select Thursday = convert(varchar(10),DATEADD(WEEK,1, @Date),120)
    SELECT @counter = @counter + 1
    Select @Date = DATEADD(WEEK,1, @Date)
    END
    Regards
    Prasad Tandel
    Please dont forget to mark as answer if this helps you :)

  • Query for getting Workcenter data

    Dear Professionals,
    I got an issue where user needs the data from the work center. So i made a query joining the table CRHD, CRCO, CRCA & CRTX here for all the Tables OBJID & OBJTY is available, but the query results in "no data found". Am i doing some mistake else is there any other way i could get the data.
    Thanks in advance
    Regards
    Prashant.Pillai

    Hi there,
    try the following:
    1. link CRHD- CRCO with left outer join - do You have the data in both table? if yes
    2. change CRHD-CRCO to inner join and add CRCA with left outer join - do You have the data?
    (No need the text tabe You can find it in add fields in query)
    Br

  • How to get table data column by column dynamically

    Hi ,
    first of all
    i have something like this
    cursor sys_cursor is
    select * from sys.all_objects;
    v_data varchar2(200);
    fetch sys_cursor
    into v_owner, v_object_name, v_subobject_name, v_object_id, v_data_object_id, v_object_type, v_created, v_last_ddl_time, v_time_stamp, v_status, v_temporary, v_generated, v_secondary;
    v_data := v_owner || ' ' || v_object_name || ' ' || v_subobject_name || ' ' ||
    v_object_id || ' ' || v_data_object_id || ' ' ||
    v_object_type || ' ' || v_created || ' ' || v_last_ddl_time || ' ' ||
    v_time_stamp || ' ' || v_status || ' ' || v_temporary || ' ' ||
    v_generated || ' ' || v_secondary;
    encrypt(v_data);
    it is ok for "sys.all_objects" but i need to modify this for all tables
    so , i need to know column names of table and type of it and value of it
    then i need to get column values by one by and encrypt it.
    i used dbms_sql and succeed to find column name and type
    however , i couldnt get the values.i can't use dbms_sql.column_values because i find column type dynamically.
    what can i do?
    how can i get table data by row
    and then for each row , i need to get values of columns by one by and encrypt those values.
    any idea is appriciated.
    thanks
    Aykut

    Dynamic SQL is the solution. Right from getting the column names, their data types to passing the string to encrypt function that you have.
    You will need to handle datatypes like LONG, LOB etc... as they cannot be concatenated with strings.
    Also, you need to manage dates and numbers.
    Obviously this would be very complicated code.
    Even if you decide to code the procedure to encrypt tables one by one, still you need to make this procedure dynamic to handle above situations.

  • Getting the data for last month of every year

    Hi,
           How to declare the date if we want to pull the data from the December of every year.
    For example if the query is run in march 2015 and they want the historical data it should pull only the data from dec 2014.
    In the same way if they ran the query in future jun 2016 and if they want to historical data it should pull only data from dec 2015.
    It should not coded manually. Please help me with date format that need to used.
    BALUSUSRIHARSHA

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    A table has to have a key to be table.  Here is my guess at a repair job: 
    CREATE TABLE Test_Data
    (pu_id INTEGER NOT NULL
      REFERENCES PU(pu_id),
     pu_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
     PRIMARY KEY (pu_id, pu_date),
     x_count INTEGER,
     y_count INTEGER);
    Identifiers are not numeric in a good schema. What math do you do with them? They are also the key in the table that models the entity they identify. Where is the PU table (and what is a PU anyway)? 
    INSERT INTO Test_Data
    VALUES
    (28, '2014-01-01', 10, 20), -- crap! No key in this mess!! 
    (28, '2015-01-01', 30, 20), -- 
    (28, '2014-12-12', 10, 20), 
    (28, '2015-02-02', 10, 20);
    A PIVOT is not a query and not even part of SQL. It is how Microsoft programmers who do not know RDBMS or have a report writer violate the tiered architecture of SQL. We also do not use XML mixed in SQL. It is a bitch to maintain, has poor performance and again
    violates the tiered architecture principle. 
    A query is not sorted because it is a table. A file in COBOL can be sorted and that seems to be what you really want to write. 
    Old COBOL love the Sybase CONVERT() string function to avoid SQL temporal data. 
    We never use SELECT * in production code; Google it. Not only are you generating code, you are generation bad code. 
    Since SQL is a database language, we prefer to do look ups and not calculations. They can be optimized while temporal math messes up optimization. A useful idiom is a report period calendar that everyone uses so there is no way to get disagreements in the DML.
    The report period table gives a name to a range of dates that is common to the entire enterprise. 
    CREATE TABLE Month_Periods
    (month_name CHAR(10) NOT NULL PRIMARY KEY
       CHECK (month_name LIKE <pattern>),
     month_start_date DATE NOT NULL,
     month_end_date DATE NOT NULL,
      CONSTRAINT date_ordering
        CHECK (month_start_date <= month_end_date),
    etc);
    These report periods can overlap or have gaps. I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601
    data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
    This will port and waste time calling string function row by row. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for