Query help on Previous record

  • Hello experts,

    -----------------------------------------------------------

    I have below data

    IDstartenddate p1p2Update date

    31441872015-07-01 00:00:00.0002015-12-31 00:00:00.00018005test1 2015-09-18 12:28:05.197

    30965052014-12-06 00:00:00.0002015-05-20 00:00:00.00018005test1 2015-08-31 12:24:59.353

    30071232014-12-06 00:00:00.0002015-06-30 00:00:00.00018005test1 2015-07-14 12:56:57.683

    When the user selects a date range from '07/01/2015' to '07/20/2015' for the update date. I need result like below (both matched record and data from previous record)

    30965052014-12-06 00:00:00.0002015-05-20 00:00:00.00018005test1 2015-08-31 12:24:59.353

    30071232014-12-06 00:00:00.0002015-06-30 00:00:00.00018005test1 2015-07-14 12:56:57.683

    ----------------------------------------------------

    create table #test (id integer,start datetime,enddate datetime, p1 integer,p2 varchar(20), updatedate datetime)

    insert into #test

    values (3144187,'2015-07-01 00:00:00.000','2015-12-31 00:00:00.000',18005,'test1','2015-09-18 12:28:05.197')

    insert into #test

    values (3096505,'2014-12-06 00:00:00.000','2015-05-20 00:00:00.000',18005,'test1','2015-08-31 12:24:59.353')

    insert into #test

    values (3007123,'2014-12-06 00:00:00.000','2015-06-30 00:00:00.000',18005,'test1','2015-07-14 12:56:57.683')

  • Crosspost... original is here:

    http://www.sqlservercentral.com/Forums/Topic1739452-3077-1.aspx#bm1739455

    (Should actually be in 2014).

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

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