Which of the following query is better... This is just an example, there are numerous situations, where I want the user name to be displayed instead of UserID
The inline SQL JOIN
will usually be better than the scalar UDF as it can be optimised better.
When testing it though be sure to use SQL Profiler to view the cost of both versions. SET STATISTICS IO ON
doesn't report the cost for scalar UDFs in its figures which would make the scalar UDF version appear better than it actually is.