Executing Function as Procedure in SQL Server
Hello to everyone,
In this article, I will try to give you information about running the function like a procedure in SQL Server.
There are those among us who know, but since they do not tell such a subject, I will tell.
You can do this easily using the code below.
--Test function creation CREATE FUNCTION TestFunction ( @ad NVARCHAR(50) ) RETURNS NVARCHAR(100) AS BEGIN RETURN 'Hello ' + @ad + ' how ara you?'; END; --Executing the function as a procedure DECLARE @functionname NVARCHAR(100); EXEC @functionname = dbo.TestFunction 'Yavuz Selim'; PRINT @functionname;
When you run the above code block, you will see the following result.
As you can see, we created a function and created a parameter to hold the name of this function and ran this parameter with EXEC. If you have specified a parameter in the function, you should also use it. The above example is already a parameterized example.
Good luck to everyone in business and life.