Query to get the last added record in a table for a particular id

T
Hi,
I have 2 tables A, B
Table A has id,name
Table B had parentid(foreignkey referring to ID in above table), record_type,created_timestamp
I want to get the last added record_type from Table B for all the ids present in Table A.

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. I know this is
a skeleton, but could you at least try to do good programming? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
This is minimal polite behavior on SQL forums. And sample data also helps. 
I have 2 tables: Alphas, Betas
CREATE TABLE Alphas
(alpha_id CHAR(10) NOT NULL PRIMARY KEY,
 alpha_name VARCHAR(25) NOT NULL);
Why was that DDL so hard you could not write it? But your narrative about the second table does not tell us if it has a key. I will guess that it is also alpha_id, but thanks to your rudeness, that is all we can do. 
CREATE TABLE Beta 
(alpha_id CHAR(10) NOT NULL PRIMARY KEY
   REFERENCES Alphas (alpha_id),
 record_type CHAR(2) NOT NULL,
 creation_timestamp DATETIME2(0) DEFAULT CURRENT_TIMESTAMP
      NOT NULL,
>> I want to get the last added record_type from Table Beta for all the ids present in Table A.<<
Think about this. Since Beta.alpha_id is a FOREIGN KEY to Alphas, all of its rows will have a match to Alpha. The SQL engine does this for you! 
SELECT *
FROM (SELECT alpha_id, record_type, creation_date,
              MAX(creation_date) OVER () AS creation_date_max
        FROM Betas)
WHERE creation_date = creation_date_max;
--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

Similar Messages

  • How can I get the last / newest record of a table?

    Hi,
    I am developing an ecard app that has a create greeting page, a preview page with edit and send buttons and an edit page.
    I got he insert working, and on the preview page I created a master record page (displays all records), and delete all unecessary designs. Doing it this way also gives me the 'edit' button, so people are able to edit their page.
    How do I get only the last record displayed though? At the moment it loops through all records and displays them in sets of 10. I found the variable that holds the totla count of records ('$totalRows_rs7417_content1'), but how do I (re-)write the script so it ONLY diplays the last record?
    I need to get the ID of this record as I am writing this into the PARAMs of the object and embed tags of my message .swf (this picks up the ID and based on that sucks the greetings text out of the database via another php script.
    Also, from this page, how can I send an email to the sender (ie creator of the message) as well as the recipient? Both email addresses are in the databse so should be part of the erecord returned.
    Thanks,
    Nik

    -----
    OK, So how do I recreate what I got in a non-ADDT list?
    well, when you´re just about to display one certain record, the term "list" is somewhat inappropriate anyway.
    What you´d simply need to do IMHO, is using DW´s native functions to create the basic "SELECT * FROM table_name ORDEr BY ID DESC" query, add "LIMIT 1" manually, and display the desired "dynamic text" placeholders in 1 table cell -- don´t think there were any need for all the fancy stuff
    (sorting, filtering etc) provided by ADDT´s list, as it´s just 1 record.
    It also occurred to me just now that finding the last record that has been added *may-* notbe enough if the site gets used a lot by our executives (I am thinking of a situation where 2 or three peolpe create greetings at the same time and press submit and then getting each others messges rather than their own).
    in this case you might want to additionally store the respective executive´s "kt_login_id" session variable -- because it´s this unique "identifier" which should be used to show the last inserted record of the person who actually inserted it, means adding a "WHERE submitter_id" equals the session variable kt_login_id - clause to the query.
    When creating a non-ADDT list that´s at some point based on detecting a user session, you´ll BTW need to insert at line 1
    I can't seemt o insert it on the page as it is looking for a insert, update or delete bahaviour on the page which of course I don't have
    please search these forums for several posts I made which explain my "use dummy table" approach that´s made for cases when you actually don´t have anything to insert/update/delete, but need "something" for ADDT´s send email behaviours.
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • How to get the last inserted record from a table ?

    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

    I'm not sure about 8i features.
    I assume here that you don't have 'Date-Time' stamp columns on the table which is the easiest way to determine the last inserted row in the table.
    If not try the following :-
    select address, piece, SQL_TEXT
    from V$SQLTEXT
    where upper(sql_text) like '%INSERT INTO TABLE_NAME%'
    Substiute the TABLE_NAME with the name of the actual table.
    Have fun.
    Regards,
    Shailender
    :-) Hiee E'body
    I work on Oracle 8i and need to get the last
    record inserted in a table.
    I have tried using rownum and rowid pseudo-columns
    but that doesn't work.
    Can you please help me out ?
    :-) Have a nice time
    Vivek Kapoor.
    IT, Atul Ltd.,
    India.

  • Getting the last added record

    Hi,
    Am developing an application that needs to record some info in a user table after adding a sales invoice. What i need is an object or method that could give me the info of the last record added in the AR invoices table, i tried using the GetNewObjectKey() but i'm not sure if this method works OK in a scenario where concurrence situations could be present, i mean in situations where multiple users could save documents at the same time, does not the method become imprecise?

    Hi Oscar,
    Have a look at the following post:
    Re: Getting the Document Number
    Hope this helps,
    Owen

  • Different ways to get the last 5 records ordered by date

    I have a query no that returns the tickets ordered by moddt, modification date,
    I was thinking of adding a select on top, to get the last 5 records of that list the select already generates. An other way was to use that select to create a view,
    and get the 5 last records that way. I also though of a possibly impossible cursor with a sequence, but hmm well I consider that not a good solution.
    So I'm trying to find a way, using a select, the topmost select which is not completed yet, to get the last 5 records. Maybe I should just try the rownumber thing again or something likewise.
    Select * from(
    select * from(
    Select ticketid, appliecatiecd, categorieid, substr(titel,&,200)||' ...' "titel", klantproriteitid, interneprioriteitid,
    (select g.voornaam||' '||g.naam
    from gebruiker g
    Where g.gebruikerid = t.gebruikerid
    And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd))"aangemaakt door",
    (select s.statusdefoms "status"
    From status s
    Where s.statusid = t.statusid
    And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd)) "status",
    Versieid,
    Moddt,
    Row_number() over (order by ticketid desc) rn
    From ticket t
    Where applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd) )
    Order by moddt)
    Where --

    Hi Floris,
    You can also use RANK: http://www.dba-oracle.com/oracle_news/oracle_faq/faq_beg_sql_top_n_rows.htm
    Regards Pete

  • Select the last saved records in a table

    I all
    I have this struct in a table
    create table INT_OBJ
    IDOBJ NUMBER(15) not null,
    IDERP NUMBER(15),
    IDE NUMBER(15),
    CPO VARCHAR2(20),
    VLR VARCHAR2(2500),
    VLRC VARCHAR2(2500)
    How to Select the last saved records in a table. I think usea a temp table for put the last row read and begin to read in the next row.
    The table is reading each four hours.

    Theoretically it can be done with ORA_ROWSCN and enabled ROWDEPENDENCIES, but there are so many nuances, so only adding column for ordering is right.
    Regards,
    Sayan Malakshinov

  • Query to get the details of Blocking and deadlock occurred for the Day

    Hi,
       I need a query to get the details of blocking and deadlock occurred for the day.

    You havent specified which version of SQL you are using which makes it difficult to give a solution. Assuming its latest versions , by default SQL Server (in any versions) doesnt track blocking information.
    You need to run some kind of queries/traces to capture blocking. The same goes with Deadlocks where majority of the DBA's enable trace flag 1222/1205 when they suspect deadlocks happening.
    Check this link -
    http://dba.stackexchange.com/questions/10644/deadlock-error-isnt-returning-the-deadlock-sql/10646#10646
    This link gives code to get historic deadlock information. I havent used it , I just googled to get that.
    That being said if you are looking for something to capture for the future check the below links.
    Check these links on how to setup extended events to capture deadlock and blocking.
    http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/12/21/an-xevent-a-day-21-of-31-the-future-tracking-blocking-in-denali.aspx
    http://blogs.msdn.com/b/sqlserverfaq/archive/2013/04/27/an-in-depth-look-at-sql-server-memory-part-2.aspx
    http://blogs.technet.com/b/mspfe/archive/2012/06/28/how_2d00_to_2d00_monitor_2d00_deadlocks_2d00_in_2d00_sql_2d00_server.aspx
    HTH
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

  • Simple Query Question - How do I return the Last 3 records of a Table?

    Question.
    For example, I have a table that has 50 records.
    How do I, specify in SQL to only return the last 3 records of the table.
    Select a.* from table a where ????

    I was just trying to show an example to a friend on
    how something like this would work and if it was even possible. But it won't work. Here's a simple example:
    SQL> create table emp
      2  (id)
      3  as
      4  select object_id
      5  from   all_objects
      6  order  by object_id;
    Table created.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
         40830      55891
         40831      55892
         40832      55893So far, so good. These are the "last 3" rows inserted. Now delete a bunch of rows and insert 3 new ones:
    SQL> delete emp where id < 40000;
    33423 rows deleted.
    SQL> commit;
    Commit complete.
    SQL> insert into emp values (60000);
    1 row created.
    SQL> insert into emp values (60001);
    1 row created.
    SQL> insert into emp values (60002);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from  (select rownum rn
      3               ,b.*
      4         from   emp b)
      5  where  rn > ( select (max(rownum) - 3)
      6                from    emp)
      7  ;
            RN         ID
          7410      55891
          7411      55892
          7412      55893Here's the problem. Even though the "last 3 rows" are 60000 - 60002, I still get the same ones as the first query.

  • Problem getting the last database record

    I need to get the last record of my database. The only way i found to do this is to use cursor::get with DB_LAST flag.
    But using it i don't always get the last record. For instance if the database contains 5000 records i am getting record number 4864 and so on.
    What am i doing wrong?

    The DB_LAST flag is the right one to use.
    Are you sure the keys sort in the order you expect? In particular, check for little endian integers. Here is some Python code that might be instructive:
    import struct
    sorted([(struct.pack("<i", i), i) for i in xrange(5000)])[-1][1]Regards,
    Michael Cahill, Oracle Berkeley DB.

  • How to get the last inserted Autoincrement value in Java for Pervasive DB

    Hi, I need to get the last inserted auto incremented value after the record is inserted IN JAVA For ex. consider we have 4 columns for the myTable in the PERVASIVE DATABASE V10 autoid - identity column (auto increment column) userID userName pageID insertSqlExpression = insert into myTable (userID , userName, pageID) values( ? ,? ,?); prepareInsert = connection.prepareStatement(insertSqlExpression); prepareInsert .excuteUpdate; After inserting the new record how can I get the autoid value (last inserted value) in the Java. Please help me.
    Thanks in advance. Arthik

    JavaArthikBabu wrote:
    I dont have privileges to write new stored procedures in database.I need to do in the Java side only. In many databases that irrelevant. The same way you would do it in a proc can be done with the correctly conceived statement (singular.)
    For ex &#150; if we insert and then the select record's identity value as a single transaction and would this guarantee that what is returned by the select would not include inserts that another might have made?Please do not take that path unless you are absolutely certain that your database does not support any other way to do it.

  • How to get the last row of a database table.

    HI ,
    I want to get record exactly from the last row of a database table.
    How is that possible?

    Hi,
    To fetch last record from an internal table, just do find the number of records in it and read using index.
    DESCRIBE TABLE ITAB LINES L_LINES.
    READ TABLE ITAB INDEX L_LINES.
    You can also use LOOP .. ENDLOOP but the above method is better (performance wise).
    using LOOP .. ENDLOOP.
    LOOP AT ITAB.
    **do nothing
    ENDLOOP.
    **process ITAB (Header record of ITAB).
    **after ENLOOP, ITAB will have the last record of the internal table.
    [here ITAB is internal table as well as header record.]
    But what is the requirement?
    If you are looking for the current record of an employee then you can use ENDDA = HIGH_DATE.
    My advice is to review your requirement again and try to fetch only that record which you need.
    Mubeen

  • Getting the last 5 records

    I was told I should do this by date, and not buy a number. He might still be right that by date is better. But I thought that by ticketnr makes also sense, because the latest ticket, is wel normally the most recent one. I've added the check although it might not be needed, so I may remove it later.
    The idea behind it is that if, although a field that needs to be filled in would give an error if not being so, a field that needs to be filled in, isn't then that record can't be used. As that wouldn't be the case, I can remove that as well. That would make it less complex.
    The idea was that records could have been deleted, so that you get 1185 1187 1188 1189 1190 . If you just take the 5 highest ticket numbers, you would only get 4 as one is missing. So I thought that if you include a check that check if the ticketid actually used or not. I suppose it would be nicer if one could write something similar to but therefore not the same:
    if tikcetid(select ticketid into ticketidtotest from ticket where ticketid=tussenticketid;).used() = TRUE then;
    Then you would be sure it is used, and it would just pick out the last 5 ones. There could be a problem with the dates if they are mixed up, but this could be a problem not just for this. So I think it would deserve a solution on the database.
    I'm getting one error as it is now.
    Error report:
    ORA-06550: line 83, column 20:
    PLS-00103: Encountered the symbol "=" when expecting one of the following:
    . ( * @ % & = - + < / > at in is mod remainder not rem then
    <an exponent (**)> <> or != or ~= >= <= <> and or like
    between || multiset member SUBMULTISET_
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    This is about the last : Tussen_ticketid := Tussen_ticketid - 1; But isn't it normall like it stands there ?
    DECLARE
    Mrecent_ticket NUMBER;
    Tussen_ticketid NUMBER;
    Ticketid_Place2 NUMBER;
    Ticketid_Place3 NUMBER;
    Ticketid_Place4 NUMBER;
    Ticketid_Place5 NUMBER;
    Ticketid_Place1 NUMBER;
    TestVeld VARCHAR2(2000);
    Query_to_use VARCHAR2(4000) := ' SELECT ticketid, applicatiecd, '||
    ' categorieid, titel, klantprioriteitid, interneprioriteitid, gebruikerid, statusid,'||
    ' versieid FROM ticket WHERE ticketid =';
    Start_Rec_ticketid NUMBER;
    TestVeldFoundThatIsCorrect NUMBER; is NULL; BOOLEAN := FALSE;
    BEGIN
    -- TestVeldFoundThatIsCorrect := FALSE;
         SELECT Max(Ticketid) INTO Mrecent_ticket FROM Ticket ;
         Tussen_ticketid := Mrecent_ticket;
         -- of dit echt nodig is weet ik zo niet
         -- kan eventueel opgevangen worden in de hoofd loop
         -- TestVeldFoundThatIsCorrect := FALSE;
         -- mischien checken op datum die ingevuld is, die moet ingevuld zijn wil het ok zijn
         LOOP From top to bottom  Till TEstVeldFOUNDTHATISCORRECT is TRUE
         WHILE TestVeldFoundThatIsCorrect != 9999999 LOOP
                   SELECT titel INTO TestVeld FROM ticket WHERE ticketid =
                   Tussen_ticketid;
              IF TestVeld is NULL THEN
                   Tussen_ticketid := Tussen_ticketid - 1;
                   TestVeld := NULL;
              ELSE
                   TestVeldFoundThatIsCorrect := 9999999;
                   Start_rec_ticketid := Tussen_ticketid;
                   --Stop loop
              END IF;
         END LOOP;
         IF TestVeldFoundThatIsCorrect = 9999999 THEN
              Tussen_ticketid := Start_rec_ticketid;
              -- standaard is het onderstaande, bovenstaande gebeurt alleen als de bovenstaande loop
              -- gebruikt is
         ELSE
              Tussen_ticketid := Mrecent_ticket;
         END IF;
         -- mischien moet er nog een count gebeuren die kijkt hoeveel tickets er zijn in een bepaalde --
         -- periode en afhankelijk daarvan, tussen wanneer en wanneer een andere flag zetten
         --LOOP TELLER BETWEEN 1 AND  6
         While teller <= 5 LOOP
              SELECT titel INTO TestVeld FROM ticket WHERE ticketid = Tussen_ticketid;
              --Veld_dat_ingevuld_moet_zijn INTO  TestVeld FROM ticket WHERE ticketid = Tussen_ticketid;
              -- dit zou het datumveld moeten zijn
              IF TestVeld is NOT NULL THEN
                   -- dan is dat record ok voor gebruik
                   -- wel nog nakijken welke veld dat moet zijn, moet altijd ingevuld zijn
                   -- waarde doet er niet toe
                   --Query_to_use := Query_to_use || ' UNION SELECT ticketid, applicatiecd, '||
                   --' categorieid, titel, klantprioriteitid, interneprioriteitid, gebruikerid, statusid,'||
                   --' versieid FROM ticket WHERE ticketid = ';
                   IF Teller = 1 THEN
    Ticketid_place1 := Tussen_ticketid;
    Query_to_use := Query_to_use || 'Ticketid_place1';
                   ELSIF Teller = 2 THEN
    Ticketid_place2 := Tussen_ticketid;
    Query_to_use := 'UNION'||Query_to_use || 'Ticketid_place2';
                   ELSIF Teller = 3 THEN
    Ticketid_place3 := Tussen_ticketid;
    Query_to_use := 'UNION'||Query_to_use || 'Ticketid_place3';
                   ELSIF Teller = 4 THEN
    Ticketid_place4 := Tussen_ticketid;
    Query_to_use :='UNION'|| Query_to_use || 'Ticketid_place4';
                   ELSIF Teller = 5 THEN
    Ticketid_place5 := Tussen_ticketid;
    Query_to_use :='UNION'|| Query_to_use || 'Ticketid_place5';
                   ELSIF Teller = 6 THEN
                        Teller := Teller + 1;
                   END IF;
                   Teller := Teller + 1;
                   Tussen_ticketid := Tussen_ticketid - 1;
              ELSIF
                   Tussen_ticketid := Tussen_ticketid - 1;
              END IF;
         END LOOP;
         -- dbms_output.Put_line(Query_to_use);
         RETURN Query_to_use;
    END;

    DECLARE
    Mrecent_ticket NUMBER;
    Tussen_ticketid NUMBER;
    Ticketid_Place2 NUMBER;
    Ticketid_Place3 NUMBER;
    Ticketid_Place4 NUMBER;
    Ticketid_Place5 NUMBER;
    Ticketid_Place1 NUMBER;
    TestVeld VARCHAR2(2000);
    Query_to_use VARCHAR2(4000) := ' SELECT ticketid,
    applicatiecd, '||
    ' categorieid, titel, klantprioriteitid,
    interneprioriteitid, gebruikerid, statusid,'||
    ' versieid FROM ticket WHERE ticketid =';
    Start_Rec_ticketid NUMBER;
    TestVeldFoundThatIsCorrect NUMBER; --is NULL;
    --BOOLEAN := FALSE;
    EGIN
    -- TestVeldFoundThatIsCorrect := FALSE;
    Max(Ticketid) INTO Mrecent_ticket FROM Ticket ;
    ussen_ticketid := Mrecent_ticket;
         -- of dit echt nodig is weet ik zo niet
         -- kan eventueel opgevangen worden in de hoofd loop
         -- TestVeldFoundThatIsCorrect := FALSE;
    -- mischien checken op datum die ingevuld is, die
    e moet ingevuld zijn wil het ok zijn
    LOOP From top to bottom  Till
    l TEstVeldFOUNDTHATISCORRECT is TRUE
         WHILE TestVeldFoundThatIsCorrect != 9999999 LOOP
    SELECT titel INTO TestVeld FROM ticket WHERE
    ERE ticketid =
                   Tussen_ticketid;
              IF TestVeld is NULL THEN
                   Tussen_ticketid := Tussen_ticketid - 1;
                   TestVeld := NULL;
              ELSE
                   TestVeldFoundThatIsCorrect := 9999999;
                   Start_rec_ticketid := Tussen_ticketid;
                   --Stop loop
              END IF;
         END LOOP;
         IF TestVeldFoundThatIsCorrect = 9999999 THEN
              Tussen_ticketid := Start_rec_ticketid;
    -- standaard is het onderstaande, bovenstaande
    de gebeurt alleen als de bovenstaande loop
              -- gebruikt is
         ELSE
              Tussen_ticketid := Mrecent_ticket;
         END IF;
    -- mischien moet er nog een count gebeuren die kijkt
    t hoeveel tickets er zijn in een bepaalde --
    -- periode en afhankelijk daarvan, tussen wanneer en
    n wanneer een andere flag zetten
         --LOOP TELLER BETWEEN 1 AND  6
         While teller <= 5 LOOP
    SELECT titel INTO TestVeld FROM ticket WHERE
    RE ticketid = Tussen_ticketid;
    --Veld_dat_ingevuld_moet_zijn INTO  TestVeld FROM
    OM ticket WHERE ticketid = Tussen_ticketid;
              -- dit zou het datumveld moeten zijn
              IF TestVeld is NOT NULL THEN
                   -- dan is dat record ok voor gebruik
    -- wel nog nakijken welke veld dat moet zijn, moet
    oet altijd ingevuld zijn
                   -- waarde doet er niet toe
    --Query_to_use := Query_to_use || ' UNION SELECT
    ECT ticketid, applicatiecd, '||
    --' categorieid, titel, klantprioriteitid,
    id, interneprioriteitid, gebruikerid, statusid,'||
                   --' versieid FROM ticket WHERE ticketid = ';
                   IF Teller = 1 THEN
    Ticketid_place1 :=
    Tussen_ticketid;
    Query_to_use :=
    Query_to_use || 'Ticketid_place1';
                   ELSIF Teller = 2 THEN
    Ticketid_place2 :=
    Tussen_ticketid;
    Query_to_use :=
    'UNION'||Query_to_use || 'Ticketid_place2';
                   ELSIF Teller = 3 THEN
    Ticketid_place3 :=
    Tussen_ticketid;
    Query_to_use :=
    'UNION'||Query_to_use || 'Ticketid_place3';
                   ELSIF Teller = 4 THEN
    Ticketid_place4 :=
    Tussen_ticketid;
    Query_to_use :='UNION'||
    Query_to_use || 'Ticketid_place4';
                   ELSIF Teller = 5 THEN
    Ticketid_place5 :=
    Tussen_ticketid;
    Query_to_use :='UNION'||
    Query_to_use || 'Ticketid_place5';
                   ELSIF Teller = 6 THEN
                        Teller := Teller + 1;
                   END IF;
                   Teller := Teller + 1;
                   Tussen_ticketid := Tussen_ticketid - 1;
              ELSIF
                   Tussen_ticketid := Tussen_ticketid - 1;
              END IF;
         END LOOP;
         -- dbms_output.Put_line(Query_to_use);
         RETURN Query_to_use;
    END;WHat are you trying to achive by this code? Please explain this bolded script part. I didn't see any function is using here. But, you are returning one value to where? Or may be i overlooked it. Please explain it.
    Regards.
    Satyaki De.

  • Getting the Last 100 Records

    Dear all.
    I have a Table with 4 million reocords,
    Is there any way to view only the last 400 commands. Is there a command in oracle that gets the first 400 or last 400 records
    Kindly Suggest

    OK. Something like this will give you the last 400 from the most recent date(s).
    select *
    from
       select col1
             ,col2
             ,col3
             ,row_number() over (order by date_loaded desc) rn
       from   your_table
    where rn <= 400;

  • Mdx query to get the last date of every month if the month is current month need current date..

    i have a scenario where i need the data of last date of every month and if the month is current month need current date data...
    is it possible using MDX...

    Hi Shashi,
    According to your description, you want to return the last day for each month except current month, right?
    In MDX, we can use ClosingPeriod function to return the member that is the last sibling among the descendants of a specified member at a specified level, here is a sample query for you reference.
    with member [measures].[a]
    as
    ClosingPeriod ([Date].[Calendar].[Date],[Date].[Calendar].currentmember).name
    select {[measures].[a]} on 0,
    [Date].[Calendar].[Month].members on 1
    from
    [Adventure Works]
    And then use the IIF function to evaluate if the month is current month. Please refer to the links below.
    http://msdn.microsoft.com/en-us/library/ms145584.aspxhttp://msdn.microsoft.com/en-IN/library/ms145994.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • To Get the earlier records in a table for a particular id neglecting the newer ones

    Hi All,
    I need to get the older records for a particular id rejecting the newer ones..My Scenarios is as follows..
    ID      Result           Date
    1        Pass             2015-01-01
    1        Fail                2015-03-05
    2       Pass                2014-06-07
    2       Fail                  2015-02-02
    My Output will be 
    ID        Result              Date
    1          Pass                2015-01-01
    2          Pass                 2014-06-07
    How can i achieve this....Thanks in advance

    Please follow the basic Netiquette of all SQL forums for the past 35+ years on the Internet. Post DDL that follows ISO-11179 rules for data element names. You have no idea; you do not even know that DATE is a reserved word in SQL! Use industry standard
    encodings (ISBN, UPC, GTIN, etc) and avoid needless dialect. Give clear specifications. Give sample data. Web need to see the keys and constraints, the DRI, etc.  80-95% of the work in SQL is in the DDL. 
    If you do not know that rows are not records, fields are not columns and tables are not files, then you should not be posting. If your tables have no keys, you should not be posting. If you have not tried any DML yourself, you should not be posting. 
    >> I need to get the older records [sic] for a particular product_id, rejecting the newer ones..My Scenarios is as follows.. <<
    Now we have to do all your typing because of your bad manners. Thanks a lot. Here is a repair job. 
    CREATE TABLE Inspections 
    (product_id CHAR(5) NOT NULL,
     inspection_date DATE NOT NULL
    PRIMARY KEY (product_id, inspection_date),
     inspection_result CHAR(4) NOT NULL
     CHECK (inspection_result IN ('pass', 'fail'))
    INSERT INTO Inspections 
    VALUES
    ('prod1', '2015-01-01', 'pass'),
    ('prod1', '2015-03-05', 'fail'),
    ('prod2', '2014-06-07', 'pass')
    ('prod2', '2015-02-02', 'fail'); 
    Here is one way to do this: 
    WITH X(product_id, inspection_date, inspection_result, first_inspection_date)
    AS 
    (SELECT product_id, inspection_date, inspection_result,
            MIN(inspection_date) OVER (PARTITION BY product_id) 
       FROM Inspections)
    SELECT product_id, inspection_date, inspection_result
     FROM X 
    WHERE first_inspection_date = inspection_date;
    --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

  • Pass selected values from a checkbox

    hello everybody i was looking for a similar thread but i couldn't find the answer i'm need, so here's my question. i have an checkbox populated from a dynamic LOV. it is showing me the correct values, but i haven't been able to receive the selected v

  • How do I change the highlight in the latest version of Pages?

    It looks like in Pages (I am currently using version 5.2) I can choose Insert > Highlight. This is great, however, how do I change the highlight color? It seems like yellow is the only option. I'm sure there is a simple and intuitive method that I am

  • St. loc. for Acct Assignment category K

    Hi Team, We have come across strange scenario while creating PO for Acct assignment categoty "K". As we know, when we are using "K" means procuring material for Cost centre (free text mtrl). For this type NO st. Loc is required as material will be di

  • Buyer Setup & Approval Escalations

    Hello, Need your help on the below issue: Today many people who have Standard PO & Blanket Release approval also have the ability to approve a Blanket Purchase Agreement. As per our business policy, we are separating Blanket Release approval (Materia

  • Trying to hook up my macbook to my tv, i have the all the cables hooked up (vga and adapter) but my screen is still black. I have a sharp aquos

    trying to display my macbook on my tv i have the apapter and the vga cables. I have watched all these youtube videos on how to do it i have also read my manuel for my tv and still it wont show up. Do you think its possibly the cable its new so not su