Skip to content
Advertisement

Recursive CTE have performace issue, need suggestion to optimize query

I wanted to get TOP 5 records from log table where “Approve date” is changed like NULL to value and vice versa. Date value is doesn’t matter, but order matters.

In this case I want first record and 5th record (Someone approved the data that’s why a value),then 7th record value is null someone rejected it.

I tried using recursive CTE it is working but for large records huge performance issue

Advertisement

Answer

You can pull out the transition records like so:

This will exhibit records where ApprovedDate transitioned from a null to a non null value (or the other way around).

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