Sql-server – calling scalar function to assign value to local variable

functionssql serverstored-procedures

In a SQL Server stored procedure, if we declare a local variable and assign the value by calling a scalar function
DECLARE @variable_name INT= dbo.scalarfuntion_name(@p1, @p2).
Would it have any impact on overall performance of SP as in general using scalar function directly into script has performance downgrade most of the times?
Thanks!

Best Answer

Two big problems with using functions in a query are that cardinalities are not accurate and that the function code is called once per row. When setting a variable neither of these are a concern. So I would think, generally speaking, there would be no measurable performance impact.