Hi @Martin Kevin
Suppose the Seqt column is the sequence column in your sample. And let us add gap Seqt value Insert into Temp values (11, '2023-10-01','2023-10-02')
in the query.
Then check this query:
;WITH CTE AS
(
SELECT *,LAG(Seqdate)OVER(ORDER BY SeqT) AS Previous_Seqdate
,LAG(SeqT)OVER(ORDER BY SeqT) AS Previous_SeqT
FROM Temp
)
SELECT SeqT,Seqdate,Pdate
FROM CTE
WHERE Seqdate<Previous_Seqdate OR SeqT-Previous_SeqT>1
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.