• Bottom line, there isn't enough informatiion in your posts for me to do anything. I don't know what an actually query is supposed to look like, I don't know what values are being passed in to the variables being used to create the dynamic sql.

    I can't go any further without all the information needed to recreate your problem. All I can to is guess and I really don't want to do that as there are also other changes that can be made to this query.