Running dates

  • Hello

    Has anyone come across an answer to this.

    Recordid 1 contact date 01/04/2011

    Recordid 2 contact date 01/05/2011

    Days between Recordid 1 contact date and recordid 2 contact date

    In this case 30 days.

  • Steve Bramwell (2/28/2012)


    Hello

    Has anyone come across an answer to this.

    Recordid 1 contact date 01/04/2011

    Recordid 2 contact date 01/05/2011

    Days between Recordid 1 contact date and recordid 2 contact date

    In this case 30 days.

    Use this datediff function.

    SELECT DATEDIFF(day, '01/04/2011'

    , '01/05/2011');

  • Are you looking for something like a self-join?

    DECLARE @tbl TABLE

    (

    Recordid INT , contact_date DATE

    )

    INSERT INTO @tbl

    VALUES (1,'20110401'),(2,'20110501');

    WITH cte AS

    (

    SELECT *, ROW_NUMBER() OVER(ORDER BY Recordid ) row

    FROM @tbl t

    )

    SELECT DATEDIFF(dd,cte1.contact_date,cte2.contact_date)

    FROM cte cte1

    INNER JOIN cte cte2

    ON cte1.row = cte2.row-1



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Cheers lutz I'll give that a go. 😛

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

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