• Thanks for the solutions,

    I tried both versions, but they are slower than my version using a local variable.

    It is strange that the execution plans are so very different between using local variables or parameters in the query..