• Bill, it's not a personal thing, we all make mistakes. The point of folks posting faster and more efficient code samples is that any posted code here in ssc could be randomly picked up and used. Folks often don't read from the beginning of a thread, nor indeed to the end, hence bad code must be flagged as such as soon as possible, preferably in the very next post and offering a properly written alternative, and an explanation. The same applies to advice and statements.

    Folks like Dwain go to considerable lengths to set a high standard for forum code and whilst there may occasionally be an element of friendly competition between ourselves, it's very rarely directed at the OP. Why bother? How important can it be to encourage coders to think about the cost of their queries? You only have to lurk around ssc for a day or two to find out that it’s absolutely vital.

    Your function is awful isn’t it? I can’t believe you saved it in your toolkit 😛

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden