Skip to content
Advertisement

Get nth result in Partition if n-1, n-2.. results are within 30 days of n

Looking for output to only have the latest episode row for each client if there are multiple episodes or a readmission in a 30 day window (30 days between end date of preceding episode(s) and start date of following episode), while also keeping episodes of that client if there was not a follow-up episode 30 days after EndDT.

Desired Output:

Simplified Code attempted:

I also don’t have DDL permissions except temp objects since this is a hosted T-SQL database

Advertisement

Answer

I think you can use lead():

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement