For question - 53430982

0

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

DECLARE @Tab TABLE
(
        itemid INT,
        itemprice INT,
        DateFrom Date
)

INSERT INTO @Tab VALUES (111,5000,'2018-01-01'),(111,8000,'2018-02-24'),(111,6000,'2018-03-12')

SELECT *,ISNULL(
        (SELECT top 1 DATEADD(day,-1,DateFrom) 
            from @tab t1 
            WHERE t1.itemid= t2.itemid
            AND t1.Datefrom > t2.Datefrom) , GETDATE()) AS DateTo 
FROM @tab t2

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results