It's not clear for me why the execution time of scalar-function could be at least two times longer than individual query, based on function's body. Details: I wrote sql-query (declaring variables as parameters) and covered it with "set statistics time on" and run it. After that I've covered the sql-query into scalar-function and executed it with statistics time on again. The result confused me: execution time in the second case was much longer than in the first case (at least two times longer).
Asked
Active
Viewed 100 times
1 Answers
0
Scalar functions need to be ran once for every row, and cannot be optimized by the query plan engine. Read more in this comment.

Community
- 1
- 1

dferidarov
- 602
- 4
- 15