Calculation date deference between two rows in same column and in same table

mytable
accountno
tdate
1001
01/01/2014
1002
01/01/2014
1003
01/01/2014
1004
01/01/2014
1005
01/01/2014
1001
01/02/2014
1002
01/02/2014
1003
01/02/2014
1004
01/02/2014
1005
01/02/2014
1001
01/03/2014
1002
01/03/2014
1003
01/03/2014
1004
01/03/2014
1005
01/03/2014
1001
01/04/2014
1002
01/04/2014
1003
01/04/2014
1004
01/04/2014
1005
01/04/2014
This is my table. I want find out account wise date deference between first date to second date, second date to third date, third date to fourth date, fourth date to fifth date........... Could you please provide me the solution with any SQL, VB or MS access
query!

In SQL 2012/2014:
SELECT accountno, tdate,
       datediff(DAY, LAG(tdate) OVER (PARTITION BY accountno ORDER BY tdate), tdate)
FROM   tbl
ORDER  BY account, tdate
In SQL 2005/2008:
; WITH CTE AS (
    SELECT accountno, tdate,
           rowno = row_number OVER (PARTITION BY accountno ORDER BY tdate)
    FROM   tbl
SELECT a.accoounno, a.tdate, datediff(DAY, b.tdate, atdate)
FROM   CTE A
LEFT   JOIN CTE B ON b.accountno = a.accountno
                 AND b.rowno     = a.rowno - 1
ORDER  BY a.accountno, a.tdate
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • How to get difference between two rows for a column field?

    hi, all,
    Could anyone show me what query statement is to get the difference betweem two rows for two column fields?
    The tables and its records are like this:
    id,      begin,      end
    p1         21          30
    p2          45          60
    p3          120          150
    I would like to have the query result like this
    id,    diff
    p1     15    --- which is 45 minus 30
    p2     60    --- which is 120 minus 60
    and so on...
    thank you in advance.
    Raffy

    You can use the LAG function to access values from previous rows:
    with q as (select 'p1' id, 21 v_start, 30 v_end from dual
    union all
    select 'p2', 45, 60 from dual
    union all
    select 'p3', 120, 150 from dual)
    select id, v_start, v_end, v_start - lag (v_end, 1, 0)
      over (order by id) v_diff from q
    ID,V_START,V_END,V_DIFF
    p1,21,30,21
    p2,45,60,15
    p3,120,150,60
    See the SQL Language doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions075.htm

  • Add new row in table between two rows - OATableBean

    Hi,
    I have a requirement where I need to add a new row between two rows. Lets say I have a table with 5 rows. I am envisioning having an icon (table switcher) on the row #1, which when clicked will insert/create a new row between rows #1 and #2 like #1.5, something that can be achieved in core forms. In core forms, when we click the add button, it immediately creates a new row before the current row ( and pushes other rows down). Is that possible with OATableBean. Please let me know if you have any ideas.
    Thanks,
    Ravi.

    Hi,
    I used following code to insert the row in the end
    public void createNewRow()
    XXEGASRLinesVOImpl vo =getXXEGASRLinesVO1();
    Row row1 ;
    int i;
    Row row[] = vo.getAllRowsInRange();
    row1 = vo.createRow(); //vo.createRowSet("10");
    vo.insertRowAtRangeIndex(row.length,row1);//.insertRow();
    row1.setNewRowState(Row.STATUS_INITIALIZED);
    Check if it works for you, you have to modify it to meet your requirement.
    Regards,
    Reetesh Sharma

  • Calculate the variance between two row

    Post Author: jane
    CA Forum: WebIntelligence Reporting
    Hi,
    I'm new to BO and wondering whether there is a way to calculate the variance between two rows. I'm working on a report which requires to display the change of two day's data. For instance, I have a table in a format as
    Date
    Sales Amount
    3/12/2008
    2300.00
    2/12/2008
    1280.00
    Changed
    1020.00
    I'd like to display the "Changed" column. Is there a way to do that in BO InfoView? In Excel, you can use the formular by identify the two cells.
    Thanks!

    Post Author: Vinl
    CA Forum: WebIntelligence Reporting
    I am having the same problem and am steping outside of the box and cannot progress.
    Seems to me that you are kind of saying that the only way to get around this is to create an individual object in Designer? I cannot find a way of cementing values as a variable in order for a variance to be created.
    I am trying to do it at column level mind you, which should not make that much difference....
    Simple SQL database. I have created an object called "Year" which takes a date and converts it to a year. I then have another object created "Total sales", put the 2 in a table get the right results...try and create a year on year variance from that...no chance...
    Used to work ok...?

  • Add space between two rows

    Hello,
    I need to add space between rows. Please let me know how to go about.
    I have a messgeComponentLayout Region, i am trying to create a space between two rows.
    Presently it is as follows:
    Vacation Plan
    Sick Plan
    I need as follows:
    Vacation Plan
    Sick Plan
    Please let me know how to go about.
    Thanks!

    The foll. is the region, how do i incorporate the rowLayout as suggested in the discussion. Please let me know.
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!-- dbdrv: exec java oracle/jrad/tools/xml/importer XMLImporter.class java &phase=dat+24 checkfile:~PROD:~PATH:~FILE &fullpath:~PROD:~PATH:~FILE -username &un_apps -password &pw_apps -dbconnection &jdbc_db_addr -userId "1" -rootPackage /oracle/apps/~PROD -rootdir &fullpath:~PROD:mds:directory -->
    <oa:header version="9.0.3.8.12_1330" xml:lang="en-US" xmlns:oa="http://xmlns.oracle.com/oa" xmlns:jrad="http://xmlns.oracle.com/jrad" xmlns:ui="http://xmlns.oracle.com/uix/ui" xmlns:user="http://xmlns.oracle.com/jrad/user" xmlns="http://xmlns.oracle.com/jrad" file-version="$Header$" text="Year to Date Accruals and Time Taken (total hrs.):" amDefName="xbol.oracle.apps.xbol.selfservice.loa.server.YtdAM">
    <ui:contents>
    <oa:messageComponentLayout controllerClass="xbol.oracle.apps.xbol.selfservice.loa.webui.MainRNCO" rows="7" columns="2" amDefName="xbol.oracle.apps.xbol.selfservice.loa.server.YtdAM" id="Main">
    <ui:contents>
    <oa:messageStyledText id="VaPlCo" prompt="US Vacation Carry Over" viewName="VacPlAcVO1" viewAttr="VacationCarryOver" styleClass="OraDataText"/>
    <oa:messageStyledText id="VaPlAc" prompt="US Vacation Plan Accrual" viewName="VacPlAcVO1" viewAttr="UsVacationPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="VaTk" prompt="Vacation Taken" viewName="VacPlAcVO1" viewAttr="VacationPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="FlPlAc" prompt="US Floating Holiday Plan Accrual" viewName="VacPlAcVO1" viewAttr="UsFloatingHolidayPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="FlTk" prompt="Floating Holiday Taken" viewName="VacPlAcVO1" viewAttr="FloatingHolidayPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="AcBaTk" prompt="Accrual Bank Taken" viewName="VacPlAcVO1" viewAttr="AccrualBankPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="item2"/>
    <oa:messageStyledText id="SiPlCo" prompt="US Sick Plan Carry Over" viewName="VacPlAcVO1" viewAttr="SickCarryOver" styleClass="OraDataText"/>
    <oa:messageStyledText id="SiPlAc" prompt="US Sick Plan Accrual" viewName="VacPlAcVO1" viewAttr="UsSickPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="SiTk" prompt="Sick Taken" viewName="VacPlAcVO1" viewAttr="SickPlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="item1" rendered="true"/>
    <oa:messageStyledText id="PePlAc" prompt="US Personal Leave Plan Accrual" viewName="VacPlAcVO1" viewAttr="UsPersonalLeavePlan" styleClass="OraDataText"/>
    <oa:messageStyledText id="PeTk" prompt="Personal Taken" viewName="VacPlAcVO1" viewAttr="PersonalLeavePlan" styleClass="OraDataText"/>
    </ui:contents>
    </oa:messageComponentLayout>
    </ui:contents>
    </oa:header>

  • Error 33172 occurred at Read & Write data transfer between two or more PF2010 controller

    Hi,i need to do data transfer between two or more FP2010 controller.e.g. FP2010(A) & FP2010(B).
    FP2010(A) need to transfer the measurement (from its I/O module) to FP2010(B) to do the data analysis.These data transfer should be synchronous btw two controller to prevent data lost.
    From the vi used in the attachment,i encountered some problems at:
    (1) Error 33172 occurred while publishing the data.Can i create and publish data under different item name?
    (2) How to synchronies the read & write btw contorller?
    All controller are communicating with each other directly without the need of a host computer to link them together
    Is there any other method to do fast data transfer betwe
    en controller?

    Hi YongNei,
    You were succesful in omiting enough information to make it very difficult to answer!
    Please post your example.
    Please tell us what version of LV-RT you are using.
    Please define what you concider "fast data transfer".
    Have you concidered mapping the FP tags of FP2010(A) to FP2010(B) and vise versa?
    WHat exactly has to be syncronized?
    If you have something that is close to working, share that.
    Well, that as far as I can go with the info you have provided. Depending on the details, what you are asking could be anything from trivial to impossible with the currently available technology. I just can't say.
    It would probably be a good idea to start over with a fresh question (sorry) because not many people are going to know what a a "
    PF2010" is and I can not guarentee that I will be able to get back to you personally until next week-end.
    Trying to help you get an answer,
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • I need to retrieve the a set of rows in between two rows from a table.

    consider employees table and primary key employee_id.
    With out using EMPLOYEE_ID column in the where clause or between clause, I need to get the records between 104 and 116 or a set of records between two rows.
    Can any one help me in this... i know this is simple but am just a fresher to oracle development... help me grow....
    Thanks,
    Arun

    ya at last i got the out put... thank guys for thinking with me....
    SELECT rownum, employee_id FROM (SELECT rownum, employee_id FROM employees ORDER BY employee_id)
    WHERE ROWNUM <=8
    MINUS
    SELECT rownum, employee_id FROM (SELECT rownum, employee_id FROM employees ORDER BY employee_id) WHERE ROWNUM <= 4

  • Insert table in between two rows of the table in Web dynpro abap.

    Hi All,
    I have a requirment like this,
    while click on a hide/show button from the first row and last column of the table, want to display  a table(or add some rows to insert data) in between the  rows of the table and insert data in the new table .
    please help me wheather it is possible or not?
    Thanks,
    Raju.

    hi raju....
           if you want to insert rows.... then read the index of the row clicked and then read the node that is bound to the table and insert an empty row at that index and bind it back again....
           if you want another table then make use of table popin.
    --regards,
      alex b justin

  • Dont want to show the divided line between two rows in a Grid.

    Hello Friends,
    I want a Grid in which I want multiple rows but i dont want to show the divided line between two rows.
    It is just like a grid on Territories form(Administrator->SetUp->General->Territories)
    Thanks.

    Mithun,
    The component you're talking about is not a grid, and that component is not exposed by the UI API so you cannot use it.
    Regards,
    Vítor Vieira

  • Including a JDialog or JFrame between two rows in a JTable

    Hello,
    Is it possible to include a JFrame or JDialog between two rows in a JTable?
    I would like two have a JFrame or JDialog which shift all the rows below the row that I want in order to include a JFrame between them.
    Thank in advance

    [http://forums.sun.com/thread.jspa?threadID=5331582]

  • Data mismatch between two clients

    Hi,
    I have a query on data mismatch between two clients.
    For eg assume a functional consultant would have configured intially some 5 custom document types and captured that in a transport request (TR1234) and promoted from one system/client (in my case QG1/821) to another system/client (say QG4/821). Again he would have configured another 3 custom document types and put in a transport request (TR4567) and promoted it. The transport request TR4567 some how did not reach QG4/821. Hence it shows only 5 records in T003 table (document types table) in QG4/821 and 8 records in QG1/821. How do we identify which is the correct transport (in this case TR4567), so that this transport can be promoted to QG4/821, so that both QG1/821 and QG4/821 are in sync.
    Similary such a discrepancy exists for custom tables also. I am not able to catch hold of any basis people for inputs on this. Hence pls advise.
    Regards
    Vimal Kumar

    development objects can be compared using, Compare the active versions in both the system. (Use remote comparision)
    But this you have to maually check.

  • How to get space between two values in a single cell of a table.

    hello,
            how to get space between two values in a single cell of a table.
    thanks a lot.
    kailash.

    sorry i got the answer.

  • Passing Parameters For Same Columns In 2 Different Tables

    OBIEE 11g
    I have 2 different dimension tables in my Subject Area.
    Dim1 has following columns: Promotion Code, Promotion Description, Promotion Date
    Fact1 has following columns: a_count, b_count, c_count
    Dim2 has following columns: Promotion Code, Promotion Description, Promotion Date
    Fact2 has following columns: a_count, b_count, c_count, d_count
    Report 1 has following columns: Promotion Code, Promotion Description, Promotion Date, a_count, b_count, c_count (From Dim1 & Fact1)
    Report 2 has following columns: Promotion Code, Promotion Description, Promotion Date, a_count, b_count, c_count, d_count (From Dim2 & Fact2)
    I have tried to pass the parameters Promotion Code, Promotion Description, Promotion Date from Report 1 to Report 2 but this has not worked for me as Report 2 is not receiving the parameters. Is there a way I can do this. Thanks in advance.

    Thanks for your response Jay,
    In Report 1 I have added prompts (Prompts tab) for Promotion Code, Promotion Description and Promotion Date. I have also set the following presentation variables in the prompts:
    PromotionCode,
    PromotionDescription
    PromotionDate
    In Report 2 I then add a filter for each of the same columns and match them to the presentation variables created in Report 1 as follows:
    Promotion Code is equal to / is in @{PromotionCode}
    Promotion Description is equal to / is in @{PromotionDescription}
    Promotion Date is equal to / is in @{PromotionDate}
    My expectation is that the values in the presentation variables will be passed from the Prompts in Report 1 to the filters in Report 2. This is not what is happening. Im not sure what I am doing wrong.

  • Error: Check that sender and reciever has same contract and the same bindin

    Hi,
    I created a client proxy for a dot net web service.  Configured logical port in soamanager tcode.  Then tested the client proxy using the report program.  It gives an error response like this:
    - <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    - <s:Body>
    - <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode>
      <faultstring xml:lang="en-US">The message with Action 'http://tempuri.org/GetData' cannot be processed at the receiver,
    due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched
    Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender
    and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport,
    None).</faultstring>
      </s:Fault>
      </s:Body>
      </s:Envelope>
    I recorded the request/response in SICF tcode.  I took the request that is recorded there in SOAP UI tester, I get the correct response there.  Only when i run the client proxy from SAP it gives the above error.
    it would be great if any one has solved this before. 
    thanks in advance.
    Regards,
    Suresh.

    Hi Selva,
    Depending the ECC version you're on & the SP level, SAP note 1229690 resolves this problem.
    Regards, Trevor

  • Must have the same type and the same length

    hi experts,
    DELIVERY_PLANT  data type STRING    //from proxy class, can't be changed
          BEGIN OF ty_citem,
              article type matnr,
              werks   type werks,
           END OF ty_citem,
    LOOP AT it_items INTO lv_item.
        lv_citem-article = lv_item-article.
        lv_citem-werks = lv_item-DELIVERY_PLANT.
        APPEND lv_citem TO GT_citem.
        clear lv_citem.
      ENDLOOP.
    SELECT matnr werks
           from marc
           into table GT_marc
           for all entries in GT_citem
           where matnr = GT_citem-article  and werks = GT_citem-werks.
    error message here:When you use the addition "FOR ALL ENTRIES IN itab", the fields "WERKS"
    and "GIT_CITEM-WERKS" must have the same type and the same length.

    Hi,
    You know for statement FOR ALL ENTRIES in where clause data type and length should be match.
    As per my understanding ,here GT_citem-werks is a string. But you know data type of WERKS_D is char with lencth 4.
    Use the below select statement.
    SELECT matnr werks
           from marc
           into table GT_marc
           for all entries in GT_citem
           where matnr = GT_citem-article  and werks = GT_citem-werks+0(4).
    Thanks.
    Subhankar

Maybe you are looking for

  • Html File in SMW0 Output Error ?

    Hello All, I have a HTML file in the SMW0 Transaction. The content of the HTML File is in Spanish Language . Now when I'm using the FM CL_GUI_HTML_VIEWER in my Custom Program to display that html file content I'm getting some junk values in the outpu

  • SBOP XI 3.1 Edge Integration kit with SAP

    Hi All, Can any one tell me where can i find the integration guide for integrating SBOP XI 3.1 Edge with BW ? This is SBOP Edge and not Enterprise. I did search under http://help.sap.com/businessobjects/ but didnt not find it. Where can i find the In

  • T code for service contract pending balance

    Hi , I want to see the amount balance in a service contract . what t code or report to use to see the actual cost remianing in the service order

  • Menus appear glitchy on second monitor.

    I just started using a two monitor setup at my new job. Firefox 4 appears to work perfectly on the first monitor, but on the second monitor, right-click menus, the Firefox menu, bookmark toolbar folders, and anything else similar to that shows up fli

  • Getting all VARCHAR fields with string length different then x

    Hello, I am trying to get from a table all the rows which contain in a certain varchar field a string length different than x (5 i.e.): varchar field treds fd <- grgrt sdfsdfsdf <- fdsds the marked rows will been given out. Thanks!