• What version of SQL Server are you using? If you're using 2012, you could use something like this as the source for your dataset:

    SELECT

    custID

    ,OrderID

    ,OrderDate

    ,LAG(OrderDate) OVER (PARTITION BY custID ORDER BY OrderDate) AS PrevDate

    ,DATEDIFF(d,LAG(OrderDate) OVER (PARTITION BY custID ORDER BY OrderDate),OrderDate) As DaysSincePrevious

    FROM Sales.Orders

    ORDER BY custID, OrderDate;

    (I'm cheating and using the TSQL2012 database from MS SQL 2012 High-Performance T-SQL Using Window Functions by Itzik Ben-Gan.

    Definitely worth a read if you do this kind of thing a lot.