MVP, Author

Modify Database State Using User-defined Function

Hits: 91

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


Post a comment