Logic of Assigning values to variables in Scalar-valued Functions
Then this would always return the last item in col1.

What does &quot;last item&quot; mean?  In SQL Server, and indeed most if not all RDBMSs, there is no concept of &quot;last&quot; unless you specify an ORDER BY clause.
The apparent order of results can change drastically if the plan changes due to things like parameter sniffing, updated statistics, new or modified indexes, etc., etc.
Never1 rely on observed order behavior without an explicit ORDER BY.
This question and the attached answers make for interesting reading on the topic, as well.

Yes, I did just say never.  This instance is an exception to the rule &quot;never say never.&quot;