• What exactly are you trying to accomplish? It is not very clear from your question.

    It would also be useful if you provided table DDL, sample data and desired output (see the first link in my signature on how to do this).

    The first thing I see that is wrong is the fact you didn't alias loaddate in the WHERE clause.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP