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.

Executing Function as Procedure in SQL Server

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.

343 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!