Selection of records over 90 days

Can someone tell me a way to select all records that are older than 90 days? I have a field named PostedDate which is the date that the record was created. I use MS Access.

Thank you!

Copy the following code:

Select * from employee where startdate<>

This means:

Select * from employee where startdate<>

Tags: ColdFusion

Similar Questions

  • I need a query that selects the amount of records for each day of a table.

    I need a query that selects the amount of records for each day of a table.
    For example, the result would be:

    1 14 date
    Date 2-3

    etc.

    Any ideas?

    Sort:

    SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)

    OF COMMENTSgroup by convert (varchar, dateAdded, 112)

  • How can I move photos from one date to another in my catalog? Downloaded LR of photos taken over several days to a date. LR6 PC Win7

    How can I move photos from one date to another in my catalog? Downloaded LR of photos taken over several days to a date. LR6 Win7 PC.

    Hi bubba43,

    Please select the images in the library grid mode Module and then drag and drop them in another folder you want.

    Kind regards

    Tanuj

  • How to select a record in one table to manipulate data in a database?

    Hello community,

    Using 32-bit Labview 2015.

    I created a user interface that runs a query and retrieves my table from a sql database.

    I want to be able to manage only one record at a time by selecting the record in my table and then manipulate the data according to the needs.

    Whenever the user runs a query, I want as the first record in the table to be selected / highlighted.

    I want an indicator that is currently active.

    Then a click of a button, to be able to scroll the actively selected record.

    Once I have the selected record, I want a way to write a query to edit or delete the record.

    Is attached a photo of my query to select all of my table and connect data in my table (results).

    Attached a photo of my painting showing the timeline of my sql database.

    What is the best way to go on a record selection in a table and the modification of data with a query?

    Any help would be greatly appreciated.

    Thank you

    I guess that's not a table, but multi-column listbox.

    Right click, select--> highlight whole line selection Mode

    The value of the multicolumn listbox is the row index - you can write a local variable to highlight the line, the event structure to handle the user clicking on, etc.

    If you enable the property editable ListBox cells, you can allow users to edit the items of the listbox.

    If you want to get the data in row, you hint REF table and work with the array of strings in row - convert it to cluster, etc..

    I don't know, what type of data, it is, how you structure the database looks like, I don't even know if you use the wrapper to work with the database, I can't write queries for you.

    Something like Update Tablica Set Serial = '5' where ID = '22';

  • BlackBerry Smartphones sync deletes events iCal over 60 days.

    I'm having a problem syncing of calendar using Desktop Manager for Mac and iCal...

    Whenever I have sync, it removes all event in iCal over 60 days. The iCal settings are not set to delete past events. Furthermore, tried all the different calendar sync settings Mgr Desktop for Mac, including the synchronization only future events.

    Also, if I am able to understand why he did this, is there a way to retrieve my deleted iCal events/appointments? The time Machine, maybe?

    I use a Macbook Pro under Snow Leopard and Curve 8520.

    Any suggestion would be appreciated. Thank you.

    Hey burko74,

    Are all your events calendar being put to always keep on the BlackBerry?

    This option is found under Calendar > Options > keep appointments in calendar?

    If it is set to 60 days, change forever.  Save the changes and try to synchronize.

  • I paid for to upgrade my membership to the creative cloud, but I still can't use it. It is telking me wiat 15 minutes, but he spent over 2 days

    I paid for to upgrade my membership to the creative cloud, but I still can't use it. It is telking me wiat 15 minutes, but he spent over 2 days

    Go to Adobe Creative Cloud

    Hello

    Please disconnect applications Adobe CC and exit Adobe CC.

    Reboot the machine and then connect to the application Adobe CC and launch applications.

    Hope that helps!

    Kind regards

    Sheena

  • I want to try adobe lightroom cc that over 30 days adode can give me more then 15 days or not befor I buy

    I want to try adobe lightroom cc that over 30 days adode can give me more then 15 days or not befor I buy

    Please see: software Adobe to trial has expired at the beginning

  • record selector don't work for the specific selection of records

    Hello

    I have a problem with the record selector in the spotlight.

    I want to select specific record, but when I select the control in the record are not in the selected record tab!

    the dataservice.json and endecaBrowserService.json files are correctly set up I think. I compare it with the app to Discover, but I do not want would be the question! not that the dynamic selection of records are working properly

    endecaBrowserService.json

    {

    "host': 'W177."

    "port": "15101."

    "recSpecProp": "Product_SKU",

    "recAggregationKey": "Endeca_Rollup_Id",

    "recFilter",:

    "recImgUrlProp": "URL_Thumbnail1",

    'recDisplayProps': ['brand', 'Category_EN', 'Product_SKU'],

    "textSearchKey": "interface_EN",

    'textSearchMatchMode': 'ALLPARTIAL '.

    }

    DataService. JSON

    {

    "jcr:primaryType': ' short: unstructured."

    "host': 'W177."

    "port": "15101."

    "recordSpecName": "Product_SKU",

    "aggregationKey": "Endeca_Rollup_Id",

    «recordFilter ": «,»

    'wildcardSearchEnabled': false,

    "recordNameField": "product_name_en",

    "fields": {"Brand": "', 'Category_EN': '',' Product_SKU'": ""}

    }

    any idea

    Thank you

    What is the record specification for records that fail?  For example, I found that the editor will fail if the record ID have spaces. That is to say 'Id1 Id2'.  Our resolution after conferring with support is to add an underscore 'Id1_Id2 '.

  • Multiple selection of records in table advanced to update in the Search Page.

    Hi all

    I write the code below, to select multiple records in table advanced for the update after clicking on the button update in the Search Page.
    I write this code in Processform request, but I got the exception when I run the code below.


    If (PageContext.GetParameter ("UpdateOnSeaBtn")! = null)
    {
    Am = (XxSupppacklistAMImpl) pageContext.getApplicationModule (webBean) XxSupppacklistAMImpl;
    am.saveRollback ();
    OAViewObjectImpl upDtVO = (OAViewObjectImpl) am.findViewObject ("PackingListSeaVO");
    PackingListSeaVORowImpl line;

    HashMap vParm = new HashMap();

    Row [] rows = upDtVO.getFilteredRows ("SingleSelection", "Y");
    int fetCount = upDtVO.getRowCount ();
    System.out.println ("Teh recovered rowcount is:," + fetCount);

    RowSetIterator multiIter;
    multiIter = upDtVO.createRowSetIterator ("multiIter");
    multiIter.setRangeStart (0);
    multiIter.setRangeSize (fetCount);


    for (int i = 0; i < fetCount; i ++)
    {
    Row = (PackingListSeaVORowImpl) multiIter.getRowAtRangeIndex (i);
    If (Row.GetAttribute ("SingleSelection")! = null)
    {
    If (Row.GetAttribute ("ItemNumber")! = null)
    {
    Object vitemNum = row.getAttribute ("ItemNumber");
    System.out.println ("The selected element Num is:," + vitemNum);
    vParm.put ("ItemNumber", vitemNum);

    pageContext.setForwardURL ("OA.jsp?page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG", / / here, I got the exception below)
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    vParm,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }
    }
    }

    multiIter.closeRowSetIterator ();

    }
    }
    }

    could you, please, can someone help on this.


    I got below exception to the side server when it is run the code above.
    Error (125,48): method setForwardURL (java.lang.String, null, null, byte, java.util.HashMap, boolean, java.lang.String, byte) is not not in the interface oracle.apps.fnd.framework.webui.OAPageContext

    Kind regards

    Hello

    832859 wrote:

    for (int i = 0; i)<>
    {
    Row = (PackingListSeaVORowImpl) multiIter.getRowAtRangeIndex (i);
    If (Row.GetAttribute ("SingleSelection")! = null)
    {
    If (Row.GetAttribute ("ItemNumber")! = null)
    {
    Object vitemNum = row.getAttribute ("ItemNumber");
    System.out.println ("The selected element Num is:," + vitemNum);
    vParm.put ("ItemNumber", vitemNum);

    > pageContext.setForwardURL"OA.jsp.page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG",//here I got below exception

    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    vParm,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }
    }
    }

    -Here is you call pageContext.setForwardURL loop.
    >

    I got below exception to the side server when it is run the code above.
    Error (125,48): method setForwardURL (java.lang.String, null, null, byte, java.util.HashMap, boolean, java.lang.String, byte) is not not in the interface oracle.apps.fnd.framework.webui.OAPageContext

    -check 5th param should nt be vParm if it is null

    Finally... After the for loop ends call... y bcz assume this page grouped 10 rows can he navigate both on the next page...:

    pageContext.setForwardURL ("OA.jsp?page=/xxfls/oracle/apps/po/packlist/webui/XxSuppalistcrealistPG",
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    NULL,
    false, / / RetainAM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }

    Concerning
    Meher Irk

    Published by: Meher Irk on March 31, 2011 19:54

  • By selecting certain records by using the check box

    Hello

    I have a similar problem mentioned in this thread Re: select specific records using the checkbox I got if I have only one primary key value in the work table. I don't know how to handle it when I have several primary keys of the table I want to use for filtering?

    Thank you.

    Hello

    You can use rowid
    First report

    SELECT APEX_ITEM.CHECKBOX(1,e.rowid) chk,
    e.*
    FROM emp e
    

    Use even submit after processes.
    And target page report

    SELECT e.*
    FROM emp e
    WHERE EXISTS(
    SELECT 1
    FROM apex_collections c
    WHERE c.collection_name = 'P46COL'
    AND c.c001 = e.rowid)
    

    Kind regards
    Jari

    Published by: jarola on October 14, 2010 10:50

  • To select adjacent records of same amount

    Oracle Version = Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

    Hi gurus

    Yet once again, I need your help, I have the following data samples:

    Sample data:

    AS WITH a reference

    (

    SELECT 100 c_id,

    TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.

    TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.

    TN 55

    OF the double

    UNION ALL

    SELECT 100 c_id,

    TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.

    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

    55

    OF the double

    UNION ALL

    SELECT 200 c_id,

    TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.

    TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.

    60

    OF the double

    UNION ALL

    SELECT 200 c_id,

    TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.

    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

    75

    OF the double

    UNION ALL

    SELECT 200 c_id,

    TO_DATE (November 2, 2008 ', 'dd-mm-yyyy') Eff_dt,.

    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.

    60

    OF the double

    )

    SELECT * REFERENCE

    order by 1, 2;

    The query result

    C_ID, EFF_DT, TER_DT, TN

    100 1 NOVEMBER 06 31 OCTOBER 08 55

    100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

    200 1ST NOVEMBER 06 31 OCTOBER 08 60

    200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75

    200 2 NOVEMBER 08 TO 31 DECEMBER 15 60

    Required result

    100 1 NOVEMBER 06 31 OCTOBER 08 55

    100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

    I need to select contagious AMT against C_ID,

    If you see examples of data, then you can see that the AMT 55 is contagious against C_ID = 100.

    If you see the same date, then you can see that the AMT 65 is not contagious against C_ID = 200, there is a record that has AMT = 75.

    order by should be EFF_DT. Thanks in advance

    Concerning

    Shu

    Hi, Shu,

    979596 wrote:

    Hi Frank

    Thanks for the reply, but when I added a record more against c_id = 200 then I get a wrong result, see below:

    Examples of data

    AS WITH a reference
    (
    SELECT 100 c_id,
    TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.
    TN 55
    OF the double
    UNION ALL
    SELECT 100 c_id,
    TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
    55
    OF the double
    UNION ALL


    SELECT 200 c_id,
    TO_DATE (November 1, 2006 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (October 31, 2008 ', 'dd-mm-yyyy') Ter_dt,.
    60
    OF the double
    UNION ALL
    SELECT 200 c_id,
    TO_DATE (November 1, 2008 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
    75
    OF the double
    UNION ALL
    SELECT 200 c_id,
    TO_DATE (November 2, 2008 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
    60 DOUBLE
    UNION ALL
    SELECT 200 c_id,
    TO_DATE (November 3, 2008 ', 'dd-mm-yyyy') Eff_dt,.
    TO_DATE (December 31, 2015 ', 'dd-mm-yyyy') Ter_dt,.
    60
    OF the double
    )
    SELECT d.
    -COUNT (DISTINCT amt) over (PARTITION BY c_id) AS amt_cnt

    REFERENCE d
    order by 1, 2
    ;

    The query result

    100 1 NOVEMBER 06 31 OCTOBER 08 55

    100 1 NOVEMBER 08 TO 31 DECEMBER 15 55

    200 1ST NOVEMBER 06 31 OCTOBER 08 60

    200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75

    200 2 NOVEMBER 08 TO 31 DECEMBER 15 60

    200 3 NOVEMBER 08 TO 31 DECEMBER 15 60

    Result of your request provided without filtering on amt_cnt

    100 1 NOVEMBER 06 31 OCTOBER 08-55-1

    100 1 NOVEMBER 08 TO 31 DECEMBER 15 55 1

    200 1ST NOVEMBER 06 31 OCTOBER 08 60 2

    200 1ST NOVEMBER 08 TO 31 DECEMBER 15 75 2

    200 2 NOVEMBER 08 TO 31 DECEMBER 15 60 2

    200 3 NOVEMBER 08 TO 31 DECEMBER 15 60 2

    ...

    When I run the query I posted earlier, with new data from the sample, I get no output with c_id = 200 lines.

    Power required

    100 1 NOVEMBER 06 31 OCTOBER 08-55-1

    100 1 NOVEMBER 08 TO 31 DECEMBER 15 55 1

    200 2 NOVEMBER 08 TO 31 DECEMBER 15 60 2

    200 3 NOVEMBER 08 TO 31 DECEMBER 15 60 2

    Maybe you want something like this:

    WITH got_neighbors AS

    (

    SELECT c_id, eff_dt, ter_dt, TN

    LAG (amt) over (PARTITION BY c_id

    ORDER BY eff_dt

    ) AS prev_amt

    Advance (amt) OVER (PARTITION BY c_id

    ORDER BY eff_dt

    ) AS next_amt

    REFERENCE

    )

    SELECT c_id, eff_dt, ter_dt, TN

    OF got_neighbors

    WHERE the amt IN (prev_amt, next_amt)

    ORDER BY c_id, eff_dt

    ;

    But I'm still guessing only to your needs.

    Specifically, I guess you want to see only those rows where TN is the same as the previous amt or amt next of the same c_id, where "previous" and "next" means in order of eff_dt.  However, if this is your requirement, so I do not understand why you did not say a word about eff_dt in your explanation, since eff_dt plays an important role in this problem.

  • SELECT generate records

    Hello guys, I have some difficulty in writing of a SELECT statement. I opened a discussion on a subject like this one a few weeks ago.

    But, since I closed it, I reopen a new. Imagine the following scenario. I have a table with the documents, another with an attachment and a junction between these two table. Documents and attachments can have different version. There is a technique used for the foreign key id and the id of commercial real is the combination between document_id and version (even in version and attachment whith attachment_id).

    It is a simplified version of my reality... But let's concentrate on this simple scenario.

    -- The technical id is used for foreign keys. 
    -- [document_id is a business key and the combination of document_id version is unique]
    CREATE TABLE documents 
    (
      technical_id NUMBER(10), 
      document_id number(10),
      version number(10),
      title varchar2(100)
    );
    
    
    CREATE TABLE attachments
    (
      technical_id number(10), -- primay key 
      attachment_id number(10),  -- concat of attachment_id and version is unique!
      version number(10),
      language varchar2(100),
      title varchar2(100)
    );
    
    
    CREATE TABLE doc_attachments
    (
      document_id number(10),
      attachment_id number(10)
    );
    

    Now, imagine the following inserts.

    INSERT INTO documents(technical_id, document_id, version, title) VALUES(1, 1, 1, 'document 1 (version 1)');
    INSERT INTO documents(technical_id, document_id, version, title) VALUES(2, 1, 2, 'document 1 (version 2)');
    INSERT INTO documents(technical_id, document_id, version, title) VALUES(3, 1, 3, 'document 1 (version 3)');
    
    
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(99, 10, 1, 'fr', 'attachment 10 (version 1)');
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(98, 10, 1, 'en', 'attachment 10 (version 2)');
    INSERT INTO attachments(technical_id, attachment_id, version, language, title) VALUES(97, 10, 2, 'fr', 'attachment 10 (version 3)');
    
    
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(1, 99);
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(1, 98);
    
    
    INSERT INTO doc_attachments(document_id, attachment_id) VALUES(3, 97);
    

    In this scenario,.

    -J' have version 3 of the same document.

    -Two different attachments; one of them has two version.

    -3 links between documents and attachments.

    If you pay attention, you will notice that I have no connection between the attachment and the second version of the document. And also, I have different languages for the same attachment. In this scenario, I want to the next exit. The list of all versions of a document with their attachments (all languages) and "gaps" with attachments previous.

    The logic is a bit tricky to understand the output. Basically, for each document, I want to see all the 'last home"received for this folder. Later we hear the fixation with the largest number of version for the same id of attachment.

    doc_tech_id doc_version attac_tech_id attachment_version language
    ----------- ----------- ------------- ------------------ -------- 
             1            1            99                  1       fr -- the first and second insert are generating these two first output records.
             1            1            98                  1       en 
    
    
             2            2            99                  1       fr -- since I did not have any link between the second version of the doc and the attachment, 
             2            2            98                  1       en -- I should have exactly the same as the previous version. So I duplicate records.
             
             3            3            97                  2       fr -- I have a link in the join table between document in version 3 and the second version of the attachment.
             3            3            98                  1       en                     
    

    It is a scenario... I wonder if this is doable in a single query? Can someone help me?

    Thank you

    with

    documents such as

    (select 1 technical_id, 1 document_id, version 1, title "document 1 (version 1)" of all the double union)

    Select 2,1,2, "document 1 (version 2)" dual Union all

    Select 3,1,3, "document 1 (version 3)" of the double

    ),

    As spare part

    (select 99 technical_id, 10 attachment_id, 1 version, language 'fr', "attachment 10 (version 1)" title of all the double union)

    Select 98,10,1, 'FR', "attachment 10 (version 2)" dual Union all

    Select 97,10,2, 'fr', "attachment 10 (version 3)" of the double

    ),

    doc_attachments as

    (select 1 document_id, 99 attachment_id union double all the)

    Select 1.98 Union double all the

    Select double 3.97

    )

    Select the language, attac_tech_id, doc_tech_id, attac_version, doc_version

    from (select doc.technical_id, doc_tech_id,

    doc.version doc_version,

    ATTS.technical_id attac_tech_id,

    ATTS.version attac_version,

    ATTS. Language,

    ROW_NUMBER() over (partition doc.technical_id, atts.language, doc.version

    order by case when doc.version = 3 then atts.version to another atts.technical_id end desc

    ) rn

    document No.

    left outer join

    doc_attachments x partition by (x.attachment_id)

    On x.document_id = doc.technical_id

    inner join

    Spare atts

    On x.attachment_id = atts.technical_id

    )

    where rn = 1

    DOC_TECH_ID DOC_VERSION ATTAC_TECH_ID ATTAC_VERSION LANGUAGE
    1 1 98 1 en
    1 1 99 1 en
    2 2 98 1 en
    2 2 99 1 en
    3 3 98 1 en
    3 3 97 2 en

    the order by clause appears to produce the result you expect, but I can't explain why it should be applied

    Concerning

    Etbin

  • Select the records from the first n distinct values of column

    I need to write a query in plsql to select records for the first 3 values distinct from a single column (example below, ID) and all lines for the next 3 distinct values of column and so on until the end of the number of distinct values in a column.
    for example:
    Age of name ID
    1 abc 10
    1 def 20
    2 IA 10
    2 20 JKL
    2 mno 60
    3 10 pqr
    4 the RST 10
    4 10 TÜV
    5 vwx 10
    6 10 XYZ
    hij 6 10
    7 lmn 10
    .
    .
    .
    so now... (up to a few County)
    Result must be
    1 the application should result->
    Age of name ID
    1 abc 10
    1 def 20
    2 IA 10
    2 20 JKL
    2 mno 60
    3 10 pqr

    Query 2 should lead to->
    4 the RST 10
    4 10 TÜV
    5 vwx 10
    6 10 XYZ
    hij 6 10

    Query 3 should lead to->
    7 lmn 10
    .
    .
    9... ..
    so now...
    How to write a query for this inside a loop.

    Hello

    Thus, a panel will consist of the lowest id value, the 2nd lowest and the 3rd lower, reggardless of how many lines is involved. The next group will include the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you must assign the numbers 1, 2, 3, 4, 5, 6,... for the rows in order by id, with all lines with the same id, getting the same number and without jumping all the numbers.
    This sounds like a job for the analytical DENSE_RANK function:

    WITH     got_grp_id     AS
    (
         SELECT     id, name, age
         ,     CEIL ( DENSE_RANK () OVER (ORDER BY id)
                   / 3
                   )          AS grp_id
         FROM     table_x
    )
    SELECT     id, name, age
    FROM     got_grp_id
    WHERE     id     = 1     -- or whatever number you want
    ;
    

    If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
    See the FAQ forum {message identifier: = 9360002}

  • Selection of records based on the flag

    Hi all

    I have records as follows:

    Program name Effective_Date Valid_Flag
    N 10/02/2012 ABCD
    N 14/02/2012 ABCD
    ABCD 20/02/2012 Y
    N 01/03/2012 ABCD
    N 10/03/2012 ABCD
    ABCD 14/03/2012 Y
    N 25/03/2012 ABCD
    N 26/03/2012 ABCD
    N 27/03/2012 ABCD
    N 28/03/2012 ABCD
    N 29/03/2012 ABCD
    ABCD 25/04/2012 Y



    I have to write a select statement to keep the first record and then only pull records when the Valid_Flag has changed. The result set should be as below.

    Program name Effective_Date Valid_Flag
    ABCD 10/02/2012 N - I kept the first record
    20/02/2012 ABCD is - Valid_Flag chages to a Y for the first time and so on.
    N 01/03/2012 ABCD
    ABCD 14/03/2012 Y
    N 25/03/2012 ABCD
    ABCD 25/04/2012 Y

    If there is no change in the flag, I don't have to draw from this record. Please help with suggestions of SQL. Thanks for your time and your help.

    ssk1974 wrote:
    Hi all

    I have records as follows:

    Program name Effective_Date Valid_Flag
    N 10/02/2012 ABCD
    N 14/02/2012 ABCD
    ABCD 20/02/2012 Y
    N 01/03/2012 ABCD
    N 10/03/2012 ABCD
    ABCD 14/03/2012 Y
    N 25/03/2012 ABCD
    N 26/03/2012 ABCD
    N 27/03/2012 ABCD
    N 28/03/2012 ABCD
    N 29/03/2012 ABCD
    ABCD 25/04/2012 Y

    I have to write a select statement to keep the first record and then only pull records when the Valid_Flag has changed. The result set should be as below.

    Program name Effective_Date Valid_Flag
    ABCD 10/02/2012 N - I kept the first record
    20/02/2012 ABCD is - Valid_Flag chages to a Y for the first time and so on.
    N 01/03/2012 ABCD
    ABCD 14/03/2012 Y
    N 25/03/2012 ABCD
    ABCD 25/04/2012 Y

    If there is no change in the flag, I don't have to draw from this record. Please help with suggestions of SQL. Thanks for your time and your help.

    In the future, it would be nice if you could provide the sample data as below, I created.

    ME_XE?with data as
      2  (
      3     select 'ABCD' as col1, to_date('2/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      4     select 'ABCD' as col1, to_date('2/14/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      5     select 'ABCD' as col1, to_date('2/20/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
      6     select 'ABCD' as col1, to_date('3/01/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      7     select 'ABCD' as col1, to_date('3/10/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
      8     select 'ABCD' as col1, to_date('3/14/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual union all
      9     select 'ABCD' as col1, to_date('3/25/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
     10     select 'ABCD' as col1, to_date('3/26/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
     11     select 'ABCD' as col1, to_date('3/27/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
     12     select 'ABCD' as col1, to_date('3/28/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
     13     select 'ABCD' as col1, to_date('3/29/2012', 'mm/dd/yyyy')       as col2, 'N' as col3    from dual union all
     14     select 'ABCD' as col1, to_date('4/25/2012', 'mm/dd/yyyy')       as col2, 'Y' as col3    from dual
     15  )
     16  select *
     17  from
     18  (
     19     select
     20             col1, col2, col3,
     21             lag(col3) over (partition by col1 order by col2 asc) as last_flag
     22     from data
     23  )
     24  where last_flag    != col3
     25  or    last_flag    is null;
    
    COL1         COL2                       COL LAS
    ------------ -------------------------- --- ---
    ABCD         10-FEB-2012 12 00:00       N
    ABCD         20-FEB-2012 12 00:00       Y   N
    ABCD         01-MAR-2012 12 00:00       N   Y
    ABCD         14-MAR-2012 12 00:00       Y   N
    ABCD         25-MAR-2012 12 00:00       N   Y
    ABCD         25-APR-2012 12 00:00       Y   N
    
    6 rows selected.
    
    Elapsed: 00:00:00.08
    ME_XE?
    

    See you soon,.

  • How to select priority records

    Hi gurus,

    Here's the scenario of my problem. Records can be present/absent both in the table as follows.
    ELEMENT ID            ELEMENT DETAILS                    SOURCE  
    
    167               Some Details from S1-1          S1
    167               Some Details from S1-2          S1
    167               Some Details from S1-3          S1
    
    
    167               Some Details from S2-1          S2
    167               Some Details from S2-2          S2
    167               Some Details from S2-3          S2
    
    167               Some Details from S3-1          S3
    167               Some Details from S3-2          S3
    167               Some Details from S3-3          S3
    
                    OR records can be present as follows
    
    ELEMENT ID            ELEMENT DETAILS                    SOURCE  
    
    
    167               Some Details from S2-1          S2
    167               Some Details from S2-2          S2
    167               Some Details from S2-3          S2
    
    167               Some Details from S3-1          S3
    167               Some Details from S3-2          S3
    167               Some Details from S3-3          S3
    
                 OR  records can be present as follows
    
    ELEMENT ID            ELEMENT DETAILS                    SOURCE  
    
    167               Some Details from S1-1          S1
    167               Some Details from S1-2          S1
    167               Some Details from S1-3          S1
    
    
    
    167               Some Details from S3-1          S3
    167               Some Details from S3-2          S3
    167               Some Details from S3-3          S3
    
    and so on ...
    The result I want

    If all the RECORDS in sources (S1, S2, S3) are present and to SELECT only data source S1
    IF S2 and S3 RECORDS present and then SELECT only data S2.
    IF S3 RECORDS present data and then SELECT S3
    IF S1 and S3 RECORDS present data only SELECT S1
    IF S1 and S2 RECORDS then present S1 only SELECT data

    for example, S1 is on the highest priority, as appropriate and then S2 and S3 last.

    How to write a select based on above logic.

    Structure table data and the sample are less than
    create table element_priority(element_id number,element_details varchar2(100),source varchar2(100) )      
           
    insert into element_priority
    select * from (
    WITH T1 AS(
       SELECT    167, 'Some Details from S1-1',  'S1' from dual
       union
       SELECT    167, 'Some  Details from S1-2',  'S1' from dual
       union
       SELECT    167, 'Some Details from S1-3',  'S1' from dual
       union
       SELECT    167, 'Some Details from S2-1',   'S2' from dual
       union
       SELECT    167, 'Some Details from S2-2',   'S2' from dual
       union
       SELECT    167, 'Some Details from S2-3',   'S2' from dual
       union
        SELECT    167, 'Some Details from S3-1',   'S3' from dual
       union
       SELECT    167, 'Some Details from S3-2',   'S3' from dual
       union
       SELECT    167, 'Some Details from S3-3',   'S3' from dual
       )
       select * from   t1
    )
    Any help would be very appreciated

    Thanks in advance

    Use an analytic RANK(), DENSE_RANK() as ROW_NUMBER() according to what is required - perhaps DENSE_RANK or RANK what you have said and the possibility of having several #1 rankings in the same partition.

    Not sure if the precise logic is clear, but something like this:

    SQL> WITH T1(element_id, element_details, source) AS(
      2     SELECT    167, 'Some Details from S1-1',  'S1' from dual
      3     union
      4     SELECT    167, 'Some  Details from S1-2',  'S1' from dual
      5     union
      6     SELECT    167, 'Some Details from S1-3',  'S1' from dual
      7     union
      8     SELECT    167, 'Some Details from S2-1',   'S2' from dual
      9     union
     10     SELECT    167, 'Some Details from S2-2',   'S2' from dual
     11     union
     12     SELECT    167, 'Some Details from S2-3',   'S2' from dual
     13     union
     14      SELECT    167, 'Some Details from S3-1',   'S3' from dual
     15     union
     16     SELECT    167, 'Some Details from S3-2',   'S3' from dual
     17     union
     18     SELECT    167, 'Some Details from S3-3',   'S3' from dual
     19     )
     20  select element_id
     21  ,      element_details
     22  ,      source
     23  from   (select element_id
     24          ,      element_details
     25          ,      source
     26          ,      dense_rank() over (partition by element_id
     27                                    order by decode(source, 'S1',1,'S2',2,'S3',3)) rn            
    
     28          from   t1)
     29  where  rn = 1;
    
    ELEMENT_ID ELEMENT_DETAILS         SO
    ---------- ----------------------- --
           167 Some  Details from S1-2 S1
           167 Some Details from S1-1  S1
           167 Some Details from S1-3  S1
    

Maybe you are looking for