Query for a logic

In a table i have an Filled_date which has records from 1990, But i want to pull only the records for where
the Filled_date is over 7 years ago.
Iam trying with Sysdate - But geting wrong results. Is there anyway to do this.  Thanks in advance.
     Sample Data in the column  Filled_date
     08-FEB-91
     27-AUG-03
     30-JUL-07
     Oracle Ver : 10GR2.
Thanks.

You can use INTERVAL as follows;
SQL> with t as
  2  (
  3    select     to_date('08-FEB-91','dd-MON-rr') as dt from dual union
  4    select     to_date('27-AUG-03','dd-MON-rr') as dt from dual union
  5    select     to_date('30-JUL-07','dd-MON-rr') as dt from dual
  6  )
  7  select t.dt
  8  from t
  9  where t.dt > sysdate - interval '7' year
10  /
DT
30-JUL-2007 00:00:00
SQL> with t as
  2  (
  3    select     to_date('08-FEB-91','dd-MON-rr') as dt from dual union
  4    select     to_date('27-AUG-03','dd-MON-rr') as dt from dual union
  5    select     to_date('30-JUL-07','dd-MON-rr') as dt from dual
  6  )
  7  select t.dt
  8  from t
  9  where t.dt < sysdate - interval '7' year
10  /
DT
08-FEB-1991 00:00:00
27-AUG-2003 00:00:00

Similar Messages

  • Need query for this logic..

    Hi,
    Need a SQL query to achieve this..
    Ex:
    Select object_name from user_objects where object_name in('EMP','DEPT')
    You will get 2 table names.
    DEPT
    EMP
    Now I want to count how many records are there in each table
    Output should be like
    DEPT 4
    EMP 13
    Please let me know how can we write it ?
    Thanks in Advance
    Devender

    You need to create a function to cout rows.
    Here is an example
    CREATE OR REPLACE
    FUNCTION get_rows (
         t_owner IN varchar2 default user,
        t_name IN varchar2
    RETURN  integer
    IS
         outVal integer;
    BEGIN
         select null
         into outVal
         from dba_tables
         where ( owner=t_owner )
              and ( table_name=t_name );
        execute immediate 'select count(*) from '||t_owner||'.'||t_name into outVal;
        RETURN outVal;
    EXCEPTION
         WHEN no_data_found THEN
              return null;
    END;
    /And here is the query.
    Processing ...
    select owner,object_name,get_rows(owner,object_name) n_rows
    from dba_objects
    where object_name in('EMP','DEPT')
    Query finished, retrieving results...
           OWNER                       OBJECT_NAME                                          ROWS                
    SCOTT                    EMP                                                                       14
    SCOTT                    DEPT                                                                       4
    2 row(s) retrieved

  • Need a query for this logic

    Hi
    table1
    id     cus_id     val
    boi     p          gh
    hdc    s           vc
    123    p          xy
    123    s          xz
    123   m          xb
    123  ll            zx
    Note: 123 is default values 
    o/p
    id     cus_id     val
    boi     p          gh
    boi     s          xz
    boi    m          xb
    boi     ll          zx
    hdc    s           vc
    hdc   p            xy
    hdc   m          xb
    hdc   ll           zx
    123    p          xy
    123    s          xz
    123   m          xb
    123   ll            zx

    Hi,
    Pleaes check this:
    WITH t AS
            (SELECT 'boi' id, 'p' cus_id, 'gh' val FROM DUAL
             UNION ALL
             SELECT 'hdc', 's', 'vc' FROM DUAL
             UNION ALL
             SELECT '123', 'p', 'xy' FROM DUAL
             UNION ALL
             SELECT '123', 's', 'xz' FROM DUAL
             UNION ALL
             SELECT '123', 'm', 'xb' FROM DUAL
             UNION ALL
             SELECT '123', 'll', 'zx' FROM DUAL),
         tt AS
            (SELECT *
               FROM t
              WHERE id = '123')
    SELECT a.id, b.cus_id, b.val
      FROM t a, tt b
    WHERE a.id <> '123' AND a.cus_id <> b.cus_id
    UNION ALL
    SELECT * FROM t
    order by 1;
    Cheers,
    Manik.

  • Extracting the Logical sql query for the specified report  in OBIEE 11g

    Hi ,
    I want to extract the logical SQL Query for the Particular report in OBIEE 11.1.1.5.
    Any pointers related to this will be very helpful.
    Thanks,
    Sonali

    for a try please add Logical sql view to ur report it will dispaly the Logical sql for that Report..
    Hope it will helps you.

  • Re: Query for logical database

    Hi Experts,
    can anybody giveme any link of step-by-step how to create a query from sq03,sq02,sq01 with logical database for CIK.
    if anybody have done the query for logical databse for CIK give me ur input how to create.
    Thanks in advance,
    KK.

    Hi
    Go to SQ01 -- Enviornment --Query area - select Standard area or global as you require.
    Then go to Enviornment - Infoset - search for the existing infoset if available as per your requirement or create an infoset here.
    Write the name of Infoset and click on create . Fill all the required field like name , logical database - CIK, press enter it will populate the structure of logical database CIK, you may include /exclude here the nodes, or keep it as it is.
    And press enter.
    Now you have to create Field group and the fields inside the each group.
    You may create thefield group by clicking the create icone in the right hand side of teh screen and may drag the then fields by double clicking inside the group.
    Please mainatin sequence as per the characteristic of the table, like first select masterdata then transactuional!
    Save it. It will ask you for package, but click on local object and save it.
    Go back , it will prompt for generate infoset, say yes.
    Now your new infoset is coming among other infosets. (it is advisable to search for the existing infoset if available to avoide inconsistency in infosets).
    Now select your infoset and assign this to user groups by clicking the tab for this, you need to select user groups for this infoset here, who will be authorised to use this query.You need to take care about the user group, as this will allow you to see your infoset at the time of query generation / display.
    Save it and go back and again go back.Cross check that you are in standard query area (as selected in first step)
    Now give the query name and click on create. It will show you your infoset , select that.
    It will propmt you the next screen for name , no.of columns required, output formats etc.
    Fill as required and go to basic list now you will have screen as SQVI and have to select your selection field and output filed. After selecting the required fileds save it and execute this .
    Cheers
    Mukta
    Edited by: MUKTAKUMARI on Aug 3, 2009 11:45 AM

  • What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10?

    Hi Guys,
    What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10?
    I have to write an AP Invoice Aging Report in Discoverer to show all unpaid invoices that have been transferred into GL... Business wants it to match one-to-one with the AP Trial Balance standard report...
    Business wants to run the report for any date in a past...
    The report has two parameters:
    As Of Date - the same as As of Date for the AP Trial Report
    Trial Balance Run Date - the date when Trial Balance was run...
    Conditions are:
    TRUNC(Invoice Date) <=TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    TRUNC(NVL(Payment Date,'01-JAN-5000')) > TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    TRUNC(Invoice Creation Date) <= TRUNC(NVL(TO_DATE(:Trial Balance Run Date),SYSDATE))
    Distr Accounting Date <= TRUNC(NVL(TO_DATE(:As Of Date),SYSDATE))
    NVL(Distr Creation Date,Invoice Creation Date) <= TRUNC(NVL(TO_DATE(:Trial Balance Run Date),SYSDATE))
    Show_Flag = 'YES', where:
    Show_Flag = CASE WHEN ( NVL(Cancelled Date,'01-JAN-1901') > NVL(:As Of Date,SYSDATE) AND NVL(Inv Amount Aud,0) = 0 ) THEN 'YES' ELSE ( CASE WHEN NVL(Inv Amount Aud,0) = 0 THEN 'NO' ELSE 'YES' END ) END
    There is a difference between the logic of my report, and the logic of AP Trial Balance...
    Could you please advise what I'm missing?
    Thanks,
    Iana

    What is the query for Accounts Payable Trial Balance (APXTRBAL) in 11.5.10? You can get the code by opening the report in Reports Builder and get the query.
    Or, enable trace/debug as per (FAQ: Common Tracing Techniques within the Oracle Applications 11i/R12 [ID 296559.1]).
    Thanks,
    Hussein

  • Invalid state in SQL query for a function that was created with no errors.

    SQL> CREATE OR REPLACE FUNCTION overlap(in_start1 IN TIMESTAMP, in_end1 IN TIMESTAMP, in_start2 IN TIMESTAMP, in_end2 IN TIMESTAMP) RETURN NUMBER
    2 IS
    3
    4 BEGIN
    5 IF (in_start1 BETWEEN in_start2 AND in_end2 OR in_end1 BETWEEN in_start2 AND in_end2 OR in_start2 BETWEEN in_start1 AND in_end1) THEN
    6 RETURN 0;
    7 ELSE
    8 RETURN 1;
    9 END IF;
    10 END;
    11 /
    Function created.
    SQL> show errors;
    No errors.
    SQL>
    SQL> SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0;
    SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0
    ERROR at line 1:
    ORA-06575: Package or function OVERLAPS is in an invalid state
    I do not understand why overlaps is returned as in invalid state in the query, when it was created with no errors earlier. Could anyone help me?

    Marius
    Looking at the logic you are trying to create it looks like you are looking for overlapping time periods.
    Consider two date/time ranges:
    Range 1 : T1 - T2
    Range 2 : T3 - T4
    Do they overlap?
    1) No: T1 < T4 (TRUE)  T2 > T3 (FALSE)
    T1 --- T2
               T3 --- T4
    2) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 ---------- T2
               T3 --- T4
    3) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 -------------------- T2
               T3 --- T4
    4) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
                   T1 ----- T2
               T3 --- T4
    5) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
               T1 --- T2
           T3 ------------ T4
    5) No: T1 < T4 (FALSE) T2 > T3 (TRUE)
                    T1 --- T2
           T3 --- T4Answer: Yes they overlap if:
    T1 < T4 AND T2 > T3
    So you can code the logic in your SQL as simply:
    SELECT *
    FROM tbl
    WHERE range1_start < range2_end
    AND    range_1_end > range2_startIf you go around implementing PL/SQL functions for simple logic that can be achieved in SQL alone then you cause context switching between the SQL and PL/SQL engines which degrades performance. Wherever possible stick to just SQL and only use PL/SQL if absolutely necessary.

  • Foreign Keys for a Logical Table

    Hi All,
    I want to know in which scenarios we create the Foreign Keys for a Logical Table. Once we create the foreign key for the logical table, does it mean that it will automatically override if any joins are there.
    Physical Table A, B ( no physical joins)
    Logical Table A, B (logical join B(Dim)-->A(Fact))
    created the foreign key in logical table A with B .(A.1=B.1)
    Will the rpd generate sql with A.1=B.1 join condition for reports.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    http://tinypic.com/r/jq1gkz/6
    Thanks,
    Virat

    In general when we go complex joins in Physical layer we go for Logical foreign key joins in BMM layer, best examples is SCD Type-II.
    Physical Table A, B ( no physical joins)
    -->You need to have a physical join so that this can be override by BMM layer
    created the foreign key in logical table A with B .(A.1=B.1) Will the rpd generate sql with A.1=B.1 join condition for reports.
    -->Yes you can see this join in BI Physical query.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    -->2 cases: 1)You need to delete existing logical joins 2) You might not have join in physical layer.
    Hope this helps
    Let me know for issues
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM
    BTW: You got very good name, why dont you update in your profile to see your name instead of some number
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM

  • Can any one send select query for this?

    Hi,
    can any one plese send select query for the following query.please send as early as possible.
    Loop through the I_BSID internal table to fill records in I_OUTPUT.Combine data from I_BSID, I_KNKK, I_KNKK_KNKLI, I_KNA1 and I_KNVV into I_OUTPUT based on the linking conditions .Field Description Source are
    I_OUTPUT-BUKRS     Company code     I_BSID-BUKRS
    I_OUTPUT-KUNNR     Customer number     I_BSID-KUNNR
    I_OUTPUT-NAME1     Customer Name     I_KNA1-NAME1
    I_OUTPUT-KNKLI     Credit account     I_KNKK-KNKLI
    I_OUTPUT-KDGRP     Customer Group     I_KNKK-KDGRP
    I_OUTPUT-KLIMK     Credit Limit     I_KNKK_KNKLI-KLIMK
    I_OUTPUT-KVGR1     Business Unit     I_KNVV-KVGR1
    I_OUTPUT-REBZG     Invoice Number     I_BSID-REBZG
    I_OUTPUT-BLDAT     Invoice Date     I_BSID-BLDAT
    I_OUTPUT-WAERS     Document Currency     I_BSID-WAERS
    I_OUTPUT-DUE_DATE     Due Date     Based on below
    Calculation
      Get the Payment terms days combining I_BSID and I_T052 based on the linking conditions mentioned above.    Note : a) Baseline Date : If baseline date I_BSID-ZFBDT is blank , use the Document Date.b) Payment Term Days :If I_BSID-ZBD3T is not blank, take this as Payment Term Days for Due date calculation.
                       If I_BSID-ZBD3T is Blank, then get payment term days from I_T052 based on I_BSID-ZTERM. If there are more than one record in I_T052 for the given Payment term, get the day part from baseline date and select the first record where the day limit I_T052-ZTAGG is greater than the day part.If I_BSID-ZBD3T is blank and I_BSID-ZTERM is also blank, then take Y000 (Due Immediately) as Payment term and proceed with the above logic. Set the payment term field blank while printing.
    Calculate Due date : For Debits, Determine Due Date = Baseline Date + Payment term Days(not discount days)                                                          For  Credits  Due date = Baseline date.Then, move the amount I_BSID-DMBTR to respective buckets (Not yet Due, Current Due, Past due 1-30, Past Due 31-60 etc.)  Based on the due date.
    Thanks&Regards,
    praveen kumar.A

    HI,
    To get Open Items you can use Function module:
    data:i_items TYPE STANDARD TABLE OF rfpos.
    CALL FUNCTION 'CUSTOMER_OPEN_ITEMS'
    EXPORTING
    bukrs = p_bukrs
    kunnr = wa_customer-kunnr
    TABLES
    t_postab = i_items
    EXCEPTIONS
    no_open_items = 1
    OTHERS = 2.
    Table I_items will have all the open items for that Customer in the given company code.
    Well for Clear Items: Try
    GET_CLEARED_ITEMS or FMITPOFM_CLEARED_ITEMS_GET.
    Hope it helps.
    Manish

  • Ad hoc query for  om

    Dear gurus,
    could you please tell me that ad hoc query is written by Sap functional people.like sao hr people ,or this is standard one.
    actually my DOJ and Relationship is not showing in that Ad Hoc Query report for OM.
    Pls suggest me what i need to do ,so that it will update,
    Could u pls tell me how to write this Ad hoc Query ?
    regards
    S
    Edited by: smrutipuspa on Sep 23, 2010 1:09 PM
    Edited by: smrutipuspa on Sep 23, 2010 2:03 PM

    Hi S,
    TCD SQ01,SQ02,SQ03
    for this you would have to create usergroup and infoset
    as we know LDB's are special abap program that  combines data from related tables and makes it avilable for query and programs
    Logical Database
    TCD -SE36
    PCH(Personnel Planning),PNP(HR Master Data),PNPCE(HR Master Data (Incl. Concurrent Employment)),PAP (applicant matsre data) are some LDB's(logical databses)
    Infoset are special views of LDB's and determine which tables and/or fields within a table, queries may reference
    http://www.dmgfederal.com/Resources/Articles/Article_SAPR3Infosets.asp
    usergroup are user gruped using the same application aera
    you could also try TCD SQVI-sap query viewer
    http://auditware.cyb.co.uk/downloads/SAPQuery_step_thru.pdf
    http://www.sap-img.com/abap/step-for-using-query-sq01-sq02-sq03.htm
    http://www.insightcp.com/res_15.html
    hope it helps
    No Worries
    KG
    Edited by: SAPenjoy:) on Sep 24, 2010 8:09 AM

  • Query for HRP infotypes

    Hi,
    Can anyone please give me the information about the follwing issue : How can i create a Adhoc query for JRP infotypes (IT 1000, 1001& 1002 etc).
    Requested you to please help me in this regard.
    Thanks & Regards,
    Naga

    first go to Sq02
    On the left hand side there is a field by the name of infoset.
    Give any appropriate name. Then click on create button.
    then a screen will appear , write the name. In data source field click on Logical Database . Here you have to select PNPCE, PAP, PNP according to your requirement.
    If you want to create Query on anything related to applicant select PAP. If ur query is based on Master data select PNPCE.
    After selecting click on tick mark (green in colour) which is given below. A screen with different folders of infotypes will appear. Select the required infotypes which you want accoridng to your requirement. Then click on tick mark again.
    Then click on generate button (red & white in colour) (3rd button from the left). A screen will appear with the name
    create object directory entry. Here you have to click on local object button.. you will now see that the system haas generated a Message saying "Infoset------- generated.
    In sq02 there is a button with the name Role/User Group Assignment . Assign the user group out here.
    Then go to SQ01, click on infoset query. Select ur user group. You can see the name of the query which you have created.

  • Adhoc Query for Qualifications.

    Hi Guys.
    Can some body help me creating an Adhoc Query for the active employees whose Qualifications along with there Name reflects, can somebody guide me in this regard.
    Regards,
    Venkat.

    Hi Venky,
    You can pull the qualification details using SAP quick viewer (Tcode SQVI) and using logical database PNP
    -> Go to Tcode SQVI
    -> give Query name and Create
    -> In the data source field, select Logical database
    -> In logical database give PNP or PNPCE
    -> Then in basis mode u can find IT 0024 in Planning data header
    -> and then select the list fields u need and the additional selection criteria also
    -> Then execute the query.
    With smile,
    Venkatesh kumar

  • Basic query abt business logic

    i need to have a website which will search from a database and display results is it advisable to have my business logic (i.e database query)in servlet only since it is a small aplication or i should have a different file for business logic?
    I am very new to this technologies no do not have much knowledge.
    i am thinking to use jsp for display since it automatically handles sessions.
    tia

    so i should have my database query logic
    based on search parameters in my servlet only???No
    should have a different file for business logic?Yes. Your servlet can create an object of a Search class(in a different file) and call its methods to do the searching. Then your servlet can attach the result to the request:
    request.setAttribute("someName", SearchResults);and then forward the request to the JSP using a RequestDispatcher:
    RequestDispatcher view = request.getRequestDispatcher("/results.jsp");
    view.forward(request, response);Then your jsp can retrieve the data:
    SearchResults data  = (SearchResults) request.getAttribute("someName");MVC. Model View Controller:
    Controller = servlet
    Model = Search class
    View = jsp
    Your directory structure might look something like this:
    yourApp
    --searchForm.htm
    --results.jsp
    --WEB-INF
    -------classes
    -----------com
    ---------------myWebsite
    --------------------web
    --------------------------MyServlet.class (package com.myWebsite.web;)
    --------------------model
    --------------------------Search.class (package com.myWebsite.model;)

  • Bex query for BW abap report/ transaction

    Hi Experts, Here is a scenario: I developed ABAP program in BW using multiple DSOs for complex logic. Since I cannot use abap program directly in BO reports, I need to develop a query in BW for my abap program. Is it possible to develop a bex query for BW abap report / transaction in BW? I have limited knowledge on BW and BO. Please help me. Thanks in advance Raghu

    First of all thanks for your suggestion Matthew..!
    As you said, I created virtual info cube based on function module.
    In the info cube, I defined (4)dimensions and (1)key figure.
    In the fucntion module, appropriate below parameters defined and code written for the data table (e_t_data)
    CALL ZFM_XXXXXXX 
    EXPORTING   
    i_infoprov =                " Name of InfoProvider   
    i_th_sfc =                  " rsdri_th_sfc: List of Characteristics    
    i_th_sfk =                  " rsdri_th_sfk: List of Key Figures
    *   i_t_range =                 " rsdri_t_range: Range List
    *   i_tx_rangetab =             " rsdri_tx_rangetab: Table from Range List
    *   i_first_call =              " rs_bool       First Call
    *   i_packagesize = 100000      " i             Package Size 
    IMPORTING   
    e_t_data =                  " standard table:  Data Table   
    e_end_of_data =             " rs_bool       :End of Data Reached   
    e_t_msg =                   " rs_t_msg      : BW: Table with Messages
    Test:
    Right click the info cube and choose "displayed data", immediately it triggered above function module.
    when I see the import parameters data,
    no characteristcs data in i_th_sfc. But, key figures has data (1 record) in i_th_sfk.
    Not sure, Did I missed anything? Please help me.
    Thanks in advance

  • Re: Query for Cost center actual by period.

    Hi Experts,
    Good Morning everybody,
    I want cost center actual values (with cost element) by period. I have created query through T.code-SQVI by joining tables COSP and CSKS.
    I got the report, but i cannot see the foreign currency postings in SQVI report. so there was a difference between SQVI and KSB1 report.
    Why i cannot see Foreign currency postings in SQVI report. please advise me, whether any other table that i can use in the query for cost center actuals by period.
    Thanks in advance & Points will be assign for useful answers,
    KUMAR

    See the answer in FI thread.
    Hi,
    KSB1 is based on COEP table. COSP shows only external postings. You should take COSS as well for internal postings in CO. Check the nature of the join with CSKS: notice COSP has OBJNR field which is not the same as KOSTL in CSKS.
    Anyway, I'd suggest you using not the join between tables, but one of standard logical databases SAP provides. For cost centres, you can use CIK.
    Regards,
    Eli

Maybe you are looking for