• The final select statement where you use a local variable is different to the pure select statement, it only works because you've got all the values exactly the same. So the examples you give are broken because you've been lazy and used exactly the same values.

    If your data really is like that something's wrong with the data structure.

    All this article shows is how you should never use functions unless you know exactly what they do, precisely the opposite of what you say at the beginning. In this case the function is so useless you might as well throw it away.

    My attitude with functions is avoid like the plague, as they break the rule of thinking in sets while programming SQL.