SHASHANGKA SHEKHAR'S BLOG

Hi, I am Shashangka Shekhar, Working with Microsoft Technologies. This is my personal blog where I share some of my experiences.

Modify Database State Using User-defined Function

In this post we are going to Insert data using an UDF.  We all know that User-defined functions (UDF) cannot be used to perform actions that modify the database state.

Error Occur while Inserting using UDF:

Invalid use of the side-affecting operator ‘INSERT’ within a function.

Let’s get it done. First we need to create a database & a table to perform those operations.

Create a new Database:

Create a SP:

Create UDF: Here we have dynamically build the query

then used sp_executesql system stored procedure to execute the statement.

Finally the UDF

Output:

Post a comment