Results 1 to 1 of 1
  1. #1
    Join Date
    Jun 2011
    Posts
    5

    Unanswered: Min Start Date and Max Date within 14 Days SQL 2008

    Hi


    I want to check End date is within 14 days of next row start date, If within 14 days than use first row start date and last row end date

    DECLARE @sampleData TABLE (
    id int,
    StartDate datetime,
    DEP char(1),
    EndDate datetime
    )

    SET DATEFORMAT DMY

    INSERT INTO @sampleData VALUES(1,'14/02/2011','A','14/02/2011')
    INSERT INTO @sampleData VALUES(1,'14/02/2011','A','15/02/2011')
    INSERT INTO @sampleData VALUES(1,'16/03/2011','A','25/04/2011')
    INSERT INTO @sampleData VALUES(1,'05/05/2011','A','05/05/2011')
    INSERT INTO @sampleData VALUES(1,'13/05/2011','B','16/05/2011')
    INSERT INTO @sampleData VALUES(1,'20/05/2011','B','20/05/2011')
    INSERT INTO @sampleData VALUES(1,'06/08/2011','B','08/08/2011')
    INSERT INTO @sampleData VALUES(2,'06/09/2011','B','08/09/2011')

    The results will look like this

    ID StartDate DEP EndDate
    1 14/02/2011 A 15/02/2011
    1 16/03/2011 B 20/05/2011
    1 06/08/2011 B 08/08/2011
    2 06/09/2011 B 08/09/2011
    Last edited by HUS; 06-09-12 at 12:04.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •