Mitigating Scalar UDF’s procedural code performance with SQL 2019 and Scalar UDF Inlining capabilities


 

A couple of days ago, I read the write-up of my former colleague @FranckPachot about refactoring procedural code to SQL. This is recurrent subject in the database world and I was interested in transposing this article to SQL Server because it was about refactoring a Scalar-Valued function to a SQL view. The latter one is a great alternative when it comes performance but something new was shipped with SQL Server 2019 and could address (or at least could mitigate) this recurrent scenario.

First of all, Scalar-Valued functions (from the User Defined Function category) are interesting objects for code