SQL Query to find gap in status [closed]

I need to turn this Java code into a query for the SPROC.

//Get the First TR Status History with no other status change in between
//Note: There should no status change in between. If it has status change then take the recent status history before the status change
private StatusHistory getFirstUTRStatusHistory(List<StatusHistory> statusHistoryList) {
    StatusHistory statusHistory = null;
    try {
        if(statusHistoryList != null && statusHistoryList.size() > 0) {
            statusHistory = statusHistoryList.get(0);
            for(StatusHistory currentSH: statusHistoryList){
                if(!currentSH.getUpdatedStatus().equals("TR")) {
                    break;
                } else {
                    statusHistory = currentSH;
                }
            }
        }

Was going to use a nested cursor (I have a list of customers that it goes through to get each List. But the nested cursor seems overkill, and perhaps a bad implementation

  • 2

    sample data and desired output are more helpful than cryptic java-code

    – 

  • Why not just use a join?

    – 

Leave a Comment