Comparing Data in Same Table, Row values against other Rows?

  • I have put together the following and wondered if you would take a look. It nearly works...

    This is an exact copy of 1 clients data...(obviosly not too exact!!!)

    key admission admdate disdate admtype

    12345 171 01/04/2010 01/04/2010 12

    12345 172 03/04/2010 03/04/2010 12

    12345 173 06/04/2010 06/04/2010 12

    12345 174 08/04/2010 08/04/2010 12

    12345 175 10/04/2010 10/04/2010 12

    12345 176 13/04/2010 13/04/2010 12

    12345 177 14/04/2010 15/04/2010 21

    12345 178 15/04/2010 15/04/2010 13

    12345 179 17/04/2010 17/04/2010 12

    12345 180 20/04/2010 20/04/2010 12

    12345 181 22/04/2010 22/04/2010 12

    12345 182 24/04/2010 24/04/2010 13

    12345 183 27/04/2010 27/04/2010 13

    12345 184 29/04/2010 29/04/2010 13

    The rows I am interested in are highlighted (admtype 21 and row above. I need to do a calculation to show only clients where the period from disdate on 1 row is 14 days or less than admdate on the subsequent row. I am just interested in the month of april for admdate.

    i need a query or solution that will give me the following result from the above data. With Diff being added in the result so futher calculations can be performed

    key admission admdate disdate admtype diff

    12345 177 14/04/2010 15/04/2010 21 1.

    The difference from disdate on adm 176 and adm date on 177 = 1.

    I would apprciate any help. Thanks in advance

  • suggest you take a look here

    http://qa.sqlservercentral.com/Forums/Topic986142-392-1.aspx

    seems a remarkably similar question

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • He is my boss and asked me to reaseach also. Small world.

    Sorted now Thanks anyway. I have a new question if you want to take a look:-):-):-)

    http://qa.sqlservercentral.com/Forums/Topic988072-392-1.aspx

    Cheers

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply